#!/bin/sh getTimeStamp() { (date +%F" "%T) } # $1: message, $2: level, $3: operation, $4: code writeJsonLog() { PROGRAM_NAME="cfddns" DEFAULT_CODE=99 DEFAULT_LEVEL="info" DEFAULT_MESSAGE="An unspecified error has occurred" DEFAULT_OPERATION="unspecified" if [ -z "$1" ]; then PROPS="$( jq --null-input \ --arg level "err" \ --arg pName "$PROGRAM_NAME" \ --arg operation "$DEFAULT_OPERATION" \ --arg code "$DEFAULT_CODE" \ --arg message "$DEFAULT_MESSAGE" \ '{"level":$level, "programName":$pName, "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 message "$1" \ '{"level":$level, "programName":$pName, "operation":$operation, "code":$code, "message":$message}' \ )" fi echo "$PROPS" | jq "." return } # $1: message, $2: level, $3: operation, $4: code writeJournalLog() { PROGRAM_NAME="cfddns" DEFAULT_CODE=99 DEFAULT_LEVEL="info" DEFAULT_MESSAGE="An unspecified error has occurred" DEFAULT_OPERATION="unspecified" # translate error levels if [ -z "$2" ]; then LOG_LEVEL=1 else case "$2" in "emergency" | "emerg") LOG_LEVEL=7 ;; "alert") LOG_LEVEL=6 ;; "critical" | "crit") LOG_LEVEL=5 ;; "error" | "err") LOG_LEVEL=4 ;; "warning" | "warn") LOG_LEVEL=3 ;; "notice") LOG_LEVEL=2 ;; "info") LOG_LEVEL=1 ;; "debug") LOG_LEVEL=0 ;; esac fi # log the message if [ -z "$1" ]; then logger --journald <