feature [logger] add status logging param
This commit is contained in:
@@ -4,13 +4,18 @@ getTimeStamp() {
|
||||
(date +%F" "%T)
|
||||
}
|
||||
|
||||
# $1: message, $2: level, $3: operation, $4: code
|
||||
uppercase() {
|
||||
echo "$1" | tr '[:lower:] [:upper:]'
|
||||
}
|
||||
|
||||
# $1: message, $2: level, $3: status, $4: operation, $5: code
|
||||
writeJsonLog() {
|
||||
PROGRAM_NAME="cfddns"
|
||||
DEFAULT_CODE=99
|
||||
DEFAULT_LEVEL="info"
|
||||
DEFAULT_MESSAGE="An unspecified error has occurred"
|
||||
DEFAULT_OPERATION="unspecified"
|
||||
DEFAULT_STATUS="ERR"
|
||||
|
||||
if [ -z "$1" ]; then
|
||||
PROPS="$(
|
||||
@@ -18,19 +23,21 @@ writeJsonLog() {
|
||||
--arg level "err" \
|
||||
--arg pName "$PROGRAM_NAME" \
|
||||
--arg operation "$DEFAULT_OPERATION" \
|
||||
--arg status "$DEFAULT_STATUS" \
|
||||
--arg code "$DEFAULT_CODE" \
|
||||
--arg message "$DEFAULT_MESSAGE" \
|
||||
'{"level":$level, "programName":$pName, "operation":$operation, "code":$code, "message":$message}' \
|
||||
'{"level":$level, "programName":$pName, "status":$status, "operation":$operation, "code":$code, "message":$message}' \
|
||||
)"
|
||||
else
|
||||
PROPS="$(
|
||||
jq --null-input \
|
||||
--arg level "${2:-$DEFAULT_LEVEL}" \
|
||||
--arg pName "$PROGRAM_NAME" \
|
||||
--arg operation "${3:-$DEFAULT_OPERATION}" \
|
||||
--arg code "${4:-$DEFAULT_CODE}" \
|
||||
--arg status "$(uppercase "${3:-$DEFAULT_STATUS}")" \
|
||||
--arg operation "${4:-$DEFAULT_OPERATION}" \
|
||||
--arg code "${5:-$DEFAULT_CODE}" \
|
||||
--arg message "$1" \
|
||||
'{"level":$level, "programName":$pName, "operation":$operation, "code":$code, "message":$message}' \
|
||||
'{"level":$level, "programName":$pName, "status":$status, "operation":$operation, "code":$code, "message":$message}' \
|
||||
)"
|
||||
fi
|
||||
|
||||
@@ -38,13 +45,14 @@ writeJsonLog() {
|
||||
return
|
||||
}
|
||||
|
||||
# $1: message, $2: level, $3: operation, $4: code
|
||||
# $1: message, $2: level, $3: status, $4: operation, $5: code
|
||||
writeJournalLog() {
|
||||
PROGRAM_NAME="cfddns"
|
||||
DEFAULT_CODE=99
|
||||
DEFAULT_LEVEL="info"
|
||||
DEFAULT_MESSAGE="An unspecified error has occurred"
|
||||
DEFAULT_OPERATION="unspecified"
|
||||
DEFAULT_STATUS="ERR"
|
||||
|
||||
# translate error levels
|
||||
if [ -z "$2" ]; then
|
||||
@@ -81,25 +89,27 @@ writeJournalLog() {
|
||||
# log the message
|
||||
if [ -z "$1" ]; then
|
||||
logger --journald <<end
|
||||
MESSAGE_ID=$(systemd-id128 new)
|
||||
SYSLOG_TIMESTAMP=$(getTimeStamp)
|
||||
MESSAGE_ID="$(systemd-id128 new)"
|
||||
SYSLOG_TIMESTAMP="$(getTimeStamp)"
|
||||
SYSLOG_FACILITY=3
|
||||
SYSLOG_IDENTIFIER=${PROGRAM_NAME}
|
||||
SYSLOG_IDENTIFIER="${PROGRAM_NAME}"
|
||||
PRIORITY=4
|
||||
ERRNO=${DEFAULT_CODE}
|
||||
OPERATION=${DEFAULT_OPERATION}
|
||||
MESSAGE=${DEFAULT_MESSAGE}
|
||||
ERRNO="${DEFAULT_CODE}"
|
||||
OPERATION="${DEFAULT_OPERATION}"
|
||||
MESSAGE="${DEFAULT_MESSAGE}"
|
||||
STATUS="${DEFAULT_STATUS}"
|
||||
end
|
||||
else
|
||||
logger --journald <<end
|
||||
MESSAGE_ID=$(systemd-id128 new)
|
||||
SYSLOG_TIMESTAMP=$(getTimeStamp)
|
||||
MESSAGE_ID="$(systemd-id128 new)"
|
||||
SYSLOG_TIMESTAMP="$(getTimeStamp)"
|
||||
SYSLOG_FACILITY=3
|
||||
SYSLOG_IDENTIFIER=${PROGRAM_NAME}
|
||||
PRIORITY=${LOG_LEVEL}
|
||||
ERRNO=${4:-$DEFAULT_CODE}
|
||||
OPERATION=${3:-$DEFAULT_OPERATION}
|
||||
MESSAGE=$1
|
||||
SYSLOG_IDENTIFIER="${PROGRAM_NAME}"
|
||||
PRIORITY="${LOG_LEVEL}"
|
||||
ERRNO="${5:-$DEFAULT_CODE}"
|
||||
OPERATION="${4:-$DEFAULT_OPERATION}"
|
||||
MESSAGE="$1"
|
||||
STATUS="${3:-$DEFAULT_STATUS}"
|
||||
end
|
||||
fi
|
||||
|
||||
|
||||
Reference in New Issue
Block a user