# Tiny Cloud - common script functions
# vim: ts=4 et ft=sh:

log() {
    local facility=kern
    local stderr
    local tag=$(basename "$0")
    while [ "${1:0:1}" = '-' ]; do
        case "$1" in 
            -f) facility="$2"; shift ;;
            -s) stderr=-s ;;
            -t) tag="$tag/$2"; shift ;;
        esac
        shift
    done
    local level="$1"
    [ -z "$DEBUG" ] && [ "$level" = debug ] && return
    shift

    logger $stderr -p "$facility.$level" -t "$tag" "$@"
    case "$level" in
        crit|alert|emerg) exit 1 ;;
    esac
}