2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2025-05-29 09:13:08 +00:00

40 lines
1.0 KiB
Plaintext

declare -F msgutil_r &>/dev/null || function msgutil_r {
local logserver=$1
local msgtype=$2
local msgstr=$3
local logfile=$4
if [ -z "$msgtype" ]; then
msgtype="debug"
fi
if [ -n "$logserver" ];then
logger -n $logserver -t xcat -p local4.$msgtype "$msgstr"
if [ "$?" != "0" ];then
exec 3<>/dev/udp/$logserver/514 >/dev/null 2>&1;logger -s -t xcat -p local4.$msgtype "$msgstr" 1>&3 2>&1
if [ "$?" != "0" ];then
logger -s -t xcat -p local4.$msgtype "$msgstr" 2>&1|nc $logserver 514 >/dev/null 2>&1
if [ "$?" != "0" ];then
logger -t xcat -p local4.$msgtype "$msgstr"
fi
fi
fi
else
logger -t xcat -p local4.$msgtype "$msgstr"
fi
if [ -n "$logfile" ]; then
local logdir="$(dirname $logfile)"
if [ ! -d "$logdir" ]; then
mkdir -p "$logdir"
touch "$logfile"
fi
echo "$msgstr" >> $logfile
fi
}
declare -F msgutil &>/dev/null || function msgutil {
msgutil_r "" "$@"
}