You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ngcpcfg/functions/logs

52 lines
1.2 KiB

#!/bin/bash
# Filename: /usr/share/ngcp-ngcpcfg/functions/logs
# Purpose: helper log functions for ngcpcfg
################################################################################
# console output including timestamps {{{
export timestamp_replacementchars='' # unset by default
console_output() {
if [ -z "${TIME_FORMAT:-}" ] ; then
printf -- "$*"
return 0
fi
local timestamp="$(date "$TIME_FORMAT")"
# indent depending on number of characters in date output
export timestamp_replacementchars="$(printf -- "%s: " "$timestamp" | sed 's/./ /g')"
printf -- "$timestamp ${HNAME:-}: $*"
}
# }}}
## logging functions {{{
log_info() {
logger -t ngcpcfg --id="${NGCPCFG_PID}" -- "$*"
console_output "$*\n"
}
# info without ending newline
log_info_n() {
logger -t ngcpcfg --id="${NGCPCFG_PID}" -- "$*"
console_output "$*"
}
log_warn() {
logger -t ngcpcfg --id="${NGCPCFG_PID}" -- "Warning: $*"
console_output "Warning: $*\n"
}
log_error() {
logger -t ngcpcfg --id="${NGCPCFG_PID}" -- "Error: $*"
console_output "Error: $*\n" >&2
}
log_debug() {
if [ -n "${DEBUG:-}" ] ; then
logger -t ngcpcfg --id="${NGCPCFG_PID}" -- "Debug: $*"
console_output "DEBUG: $*\n" >&2
fi
}
## }}}