]> git.ipfire.org Git - network.git/commitdiff
logging: Log calling function and hooks of messages.
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 23 Sep 2012 10:57:36 +0000 (10:57 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 23 Sep 2012 10:57:36 +0000 (10:57 +0000)
This helps to debug things more easily and
keeps stdout cleaner.

functions.logging

index 9df5ce8648542f2381746a86e3fd3841754608cf..ce0a95648fc71ea8282ac16109f13a481d7138be 100644 (file)
@@ -33,17 +33,23 @@ function log() {
        local level=${1}
        shift
        local message="$@"
+       local message_log="${message}"
 
        if [ -z "${DEBUG}" ] && [ "${level}" = "DEBUG" ]; then
                return
        fi
 
+       local funcname="${FUNCNAME[1]}"
+       if isset funcname; then
+               message_log="${funcname}: ${message_log}"
+       fi
+
        # Set a prefix if we are in a hook.
        if [ -n "${HOOK}" ]; then
-               message="${HOOK}: ${message}"
+               message_log="${HOOK}: ${message_log}"
        fi
 
-       logger -t "${LOG_FACILITY}[$$]" "${message}"
+       logger -t "${LOG_FACILITY}[$$]" "${message_log}"
 
        # Leave here, when there should be no output on the console.
        [ "${LOG_DISABLE_STDOUT}" = "true" ] && return 0