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
+19 -23
View File
@@ -24,30 +24,26 @@ 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
PROPS="$( if [ -z "$1" ] || [ $# -lt 3 ]; then
jq --null-input \ return
--arg level "err" \ fi
--arg pName "$LOG_PROGRAM_NAME" \
--arg operation "$LOG_DEFAULT_OPERATION" \ PROPS="$(
--arg status "$LOG_DEFAULT_STATUS" \ jq --null-input \
--arg code "$LOG_DEFAULT_CODE" \ --arg timestamp "$(getTimeStamp)" \
--arg message "$LOG_DEFAULT_MESSAGE" \ --arg hostname "$(getHostname)" \
'{"level":$level, "programName":$pName, "status":$status, "operation":$operation, "code":$code, "message":$message}' \ --arg pName "$LOG_PROGRAM_NAME" \
)" --arg pid = "$$" \
else --arg level "$2" \
PROPS="$( --arg status "$(uppercase "$3")" \
jq --null-input \ --arg message "$1" \
--arg level "${2:-$LOG_DEFAULT_LEVEL}" \ --arg operation "${4:UNSPECIFIED}" \
--arg pName "$LOG_PROGRAM_NAME" \ --arg code "${5:999}" \
--arg status "$(uppercase "${3:-$LOG_DEFAULT_STATUS}")" \ '{"level":$level, "programName":$pName, "status":$status, "operation":$operation, "code":$code, "message":$message}' \
--arg operation "${4:-$LOG_DEFAULT_OPERATION}" \ )"
--arg code "${5:-$LOG_DEFAULT_CODE}" \
--arg message "$1" \
'{"level":$level, "programName":$pName, "status":$status, "operation":$operation, "code":$code, "message":$message}' \
)"
fi fi
echo "$PROPS" | jq "." echo "$PROPS" | jq "."