]> git.ipfire.org Git - people/ms/network.git/blobdiff - functions.logging
hostapd: Enable WMM by default.
[people/ms/network.git] / functions.logging
index e43f64b81cbb87dbfe8f57f9d4c324bd7e69cc6a..57b432617220dfec9987b2602eaf512cdf1dbede 100644 (file)
@@ -33,26 +33,48 @@ function log() {
        local level=${1}
        shift
        local message="$@"
+       local message_log="${message}"
 
        if [ -z "${DEBUG}" ] && [ "${level}" = "DEBUG" ]; then
                return
        fi
 
+       local funcname="${FUNCNAME[1]}"
+       message_log="${funcname}: ${message_log}"
+
        # 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
 
+       local colour
+       local console="2"
        case "${level}" in
-               DEBUG|INFO|WARNING|ERROR)
-                       message="${CLR_LOG[${level}]}${message}${CLR_RESET_ALL}"
+               DEBUG)
+                       colour="${CLR_CYAN_R}"
+                       ;;
+               INFO)
+                       console="1"
+                       ;;
+               WARNING)
+                       colour="${CLR_YELLOW_R}"
+                       ;;
+               CRITICAL|ERROR)
+                       colour="${CLR_RED_B}"
                        ;;
        esac
 
-       printf "${message}\n" >&2
+       case "${console}" in
+               1)
+                       printf "${colour}${message}${CLR_RESET}\n"
+                       ;;
+               2)
+                       printf "${colour}${message}${CLR_RESET}\n" >&2
+                       ;;
+       esac
 }