#!/bin/sh

DAEMON_LOG_FACILITY="daemon"
DAEMON_LOG_NAME=$(basename $0)
DAEMON_LOG_PID=$$

daemon_log_debug () {
    daemon_log "debug" "$1"
}

daemon_log_notice () {
    daemon_log "notice" "$1"
}

daemon_log_info () {
    daemon_log "info" "$1"
}

daemon_log_warn () {
    daemon_log "warn" "$1"
}

daemon_log_err () {
    daemon_log "err" "$1"
}

daemon_log_crit () {
    daemon_log "crit" "$1"
}

daemon_log_alert () {
    daemon_log "alert" "$1"
}

daemon_log_emerg () {
    daemon_log "emerg" "$1"
}

daemon_log () {
    local PRIO=$1
    local MESSAGE=$2
    local STDERR=

    if [ "1" == "$ENABLE_DEBUG" ]; then
        STDERR="-s"
    fi

    logger ${STDERR} -t "mc.${DAEMON_LOG_NAME}[$DAEMON_LOG_PID]" -p "${DAEMON_LOG_FACILITY}.$PRIO" "$MESSAGE"
}
