#!/bin/sh
#********************************************************************************
# (c) Copyright [2021] Micro Focus or one of its affiliates.
#
# The only warranties for products and services of Micro Focus and its affiliates 
# and licensors (“Micro Focus”) are as may be set forth in the express warranty 
# statements accompanying such products and services. Nothing herein should be 
# construed as constituting an additional warranty. Micro Focus shall not be liable 
# for technical or editorial errors or omissions contained herein. The information 
# contained herein is subject to change without notice.
#********************************************************************************

# To set the log level. debug:0; info:1; warn:2; error:3
LOGLEVEL=1
LOG_FILE_PATH=""

HOSTNAME=`hostname`

function log()
{
    logtype=$1
    log_msg=$2
    datetime=`date +'%F %H:%M:%S'`
    #logformat="datetime hostname logtype log_msg"
    logformat="${datetime} [${HOSTNAME}] [${logtype}]  $log_msg"
	
    {
    case $logtype in
        debug)
            [[ $LOGLEVEL -le 0 ]] && echo -e "${logformat}" ;;
        info)
            [[ $LOGLEVEL -le 1 ]] && echo -e "${logformat}" ;;
        warn)
            [[ $LOGLEVEL -le 2 ]] && echo -e "${logformat}" ;;
        error)
            [[ $LOGLEVEL -le 3 ]] && echo -e "${logformat}" ;;
    esac
    } | tee -a $LOG_FILE_PATH
}

function log_debug()
{
        log debug "$1"
}

function log_info()
{
        log info "$1"
}

function log_warn()
{
        log warn "$1"
}

function log_error()
{
        log error "$1"
}

