# -*-Shell-script-*-
#
# functions     This file contains functions to be used by multiple releng tools.
#

function show_time () {
    num=$1
    min=0
    hour=0
    day=0
    if ((num>59)); then
        ((sec=num%60))
        ((num=num/60))
        if ((num>59)); then
            ((min=num%60))
            ((hour=num/60))
        else
            ((min=num))
        fi
    else
        ((sec=num))
    fi
    echo "$hour"h "$min"m "$sec"s
}

function get_timestamp () {
    date "+%Y-%m-%d %H:%M:%S"
}

function log_msg () {
    msg_type="$1"
    msg="$2"
    if [ "${LOGFILE}" == "" ]; then
        echo "ERROR - LOGFILE not set." >&2
	return 1
    fi
    printf "%s - %5s - %s\n" "$(get_timestamp)" "${msg_type}" "${msg}" >> ${LOGFILE}
}

function log_info () {
    log_msg "INFO " "$1"
}

function log_error () {
    error_msg="$1"
    echo "ERROR - ${error_msg}" >&2
    log_msg "ERROR" "${error_msg}"
}

