mirror of
https://asciireactor.com/otho/bash-logger.git
synced 2024-11-21 16:45:06 +00:00
45 lines
983 B
Bash
45 lines
983 B
Bash
|
#!/usr/bin/env bash
|
||
|
|
||
|
# Set syslog_local="TRUE" to only log locally.
|
||
|
|
||
|
syslog_host="syslog.adamonet"
|
||
|
syslog_port="514"
|
||
|
syslog_type="tcp"
|
||
|
syslog_facility="local7"
|
||
|
|
||
|
if [[ -z ${syslog_facility} ]]; then
|
||
|
syslog_facility="local7";
|
||
|
fi
|
||
|
message="${*:2}"
|
||
|
if [[ -z $2 ]]; then
|
||
|
priority="${syslog_facility}.info"
|
||
|
message="$1"
|
||
|
else
|
||
|
case $1 in
|
||
|
0|e*) priority="${syslog_facility}.emerg" ;;
|
||
|
1|a*) priority="${syslog_facility}.alert" ;;
|
||
|
2|c*) priority="${syslog_facility}.crit" ;;
|
||
|
3|e*) priority="${syslog_facility}.err" ;;
|
||
|
4|w*) priority="${syslog_facility}.warning" ;;
|
||
|
5|n*) priority="${syslog_facility}.notice" ;;
|
||
|
6|i*) priority="${syslog_facility}.info" ;;
|
||
|
7|d*) priority="${syslog_facility}.debug" ;;
|
||
|
*)
|
||
|
echo "Exit: invalid severity level. No log sent."
|
||
|
exit 1
|
||
|
;;
|
||
|
esac
|
||
|
fi
|
||
|
|
||
|
if [[ $syslog_local == "TRUE" ]]; then
|
||
|
logger -i \
|
||
|
-p "${priority}" \
|
||
|
"${message}"
|
||
|
else
|
||
|
logger -i --tcp \
|
||
|
-n $syslog_host \
|
||
|
-P $syslog_port \
|
||
|
-p "${priority}" \
|
||
|
"${message}"
|
||
|
fi
|