feat(logger): Update JSON logger

Require message, level, and status. Reorganize JSON output to mirror modified syslog-style structure.
This commit is contained in:
2026-07-22 22:53:38 -06:00
parent f4dc8f44b1
commit 5b55ac95a3
+13 -17
View File
@@ -24,28 +24,24 @@ writePlainTextLog() {
"$2" "$3" "$1" "${4:UNSPECIFIED}" "${5:999}" "$2" "$3" "$1" "${4:UNSPECIFIED}" "${5:999}"
} }
# $1: message, $2: level, $3: status, $4: operation, $5: code # $1: message, $2: level, $3: status, [$4: operation], [$5: code]
writeJsonLog() { writeJsonLog() {
if [ -z "$1" ]; then # not enough information to generate a meaningful log message
if [ -z "$1" ] || [ $# -lt 3 ]; then
return
fi
PROPS="$( PROPS="$(
jq --null-input \ jq --null-input \
--arg level "err" \ --arg timestamp "$(getTimeStamp)" \
--arg hostname "$(getHostname)" \
--arg pName "$LOG_PROGRAM_NAME" \ --arg pName "$LOG_PROGRAM_NAME" \
--arg operation "$LOG_DEFAULT_OPERATION" \ --arg pid = "$$" \
--arg status "$LOG_DEFAULT_STATUS" \ --arg level "$2" \
--arg code "$LOG_DEFAULT_CODE" \ --arg status "$(uppercase "$3")" \
--arg message "$LOG_DEFAULT_MESSAGE" \
'{"level":$level, "programName":$pName, "status":$status, "operation":$operation, "code":$code, "message":$message}' \
)"
else
PROPS="$(
jq --null-input \
--arg level "${2:-$LOG_DEFAULT_LEVEL}" \
--arg pName "$LOG_PROGRAM_NAME" \
--arg status "$(uppercase "${3:-$LOG_DEFAULT_STATUS}")" \
--arg operation "${4:-$LOG_DEFAULT_OPERATION}" \
--arg code "${5:-$LOG_DEFAULT_CODE}" \
--arg message "$1" \ --arg message "$1" \
--arg operation "${4:UNSPECIFIED}" \
--arg code "${5:999}" \
'{"level":$level, "programName":$pName, "status":$status, "operation":$operation, "code":$code, "message":$message}' \ '{"level":$level, "programName":$pName, "status":$status, "operation":$operation, "code":$code, "message":$message}' \
)" )"
fi fi