# Log levels for messages LLMute=0 LLMdtry=1 # mandatory: messages that are always written to the log (except mute) LLError=2 LLWarning=3 LLInfo=4 LLDebug=5 ## Actual log level of the logger used Log_Level=$LLDebug ## Name of the logging script Log_Name="myscript"; ## Write log of the script. ## $1 Loglevel to log the message with. ## $2 message to log. function logger() { local _logging_level=$1; local _log_message=$2; if [[ $Log_Level -lt $_logging_level ]]; then return; fi local _now=$($DATE +%Y%m%d_%H:%M:%S); if [[ $_logging_level -eq $LLInfo ]]; then _type=" Info:"; elif [[ $_logging_level -eq $LLError ]]; then _type=" ERROR!"; elif [[ $_logging_level -eq $LLWarning ]]; then _type=" Warning:"; elif [[ $_logging_level -eq $LLDebug ]]; then _type=" DEBUG:"; else _type=":"; fi printf "$Log_Name ${_now}${_type} ${_log_message}\n" >> $Log_File; if [[ $Log_Level -eq $LLDebug ]]; then printf "$Log_Name ${_now}${_type} ${_log_message}\n"; fi } function test() { echo $DATE } DATE=$(which date); Run_Date=$($DATE +%Y_%m_%d) Log_File="/tmp/${Run_Date}_${Log_Name}.log"; test