add trace

This commit is contained in:
Jakobus Schürz 2020-09-21 21:14:18 +02:00
parent 090e7e95b3
commit b694334bd9

View file

@ -41,7 +41,7 @@ touch $SCRIPT_LOG
export LOGLEVEL="INFO" export LOGLEVEL="INFO"
function ERROR(){ function logerror(){
local function_name="${FUNCNAME[1]}" local function_name="${FUNCNAME[1]}"
local msg="$1" local msg="$1"
timeAndDate=`date` timeAndDate=`date`
@ -54,7 +54,7 @@ function ERROR(){
echo "[$timeAndDate] [ERROR] $msg" >> $SCRIPT_LOG echo "[$timeAndDate] [ERROR] $msg" >> $SCRIPT_LOG
} }
function WARN(){ function logwarn(){
local function_name="${FUNCNAME[1]}" local function_name="${FUNCNAME[1]}"
local msg="$1" local msg="$1"
timeAndDate=`date` timeAndDate=`date`
@ -64,10 +64,10 @@ function WARN(){
if [[ ! ${loglevels[*]} =~ "${LOGLEVEL-$MYHSELLCONFIG_LOGLEVEL_DEFAULT}" ]];then if [[ ! ${loglevels[*]} =~ "${LOGLEVEL-$MYHSELLCONFIG_LOGLEVEL_DEFAULT}" ]];then
echo $msg >&2 echo $msg >&2
fi fi
echo "[$timeAndDate] [INFO] $msg" >> $SCRIPT_LOG echo "[$timeAndDate] [WARN] $msg" >> $SCRIPT_LOG
} }
function INFO(){ function loginfo(){
local function_name="${FUNCNAME[1]}" local function_name="${FUNCNAME[1]}"
local msg="$1" local msg="$1"
timeAndDate=`date` timeAndDate=`date`
@ -81,7 +81,7 @@ function INFO(){
} }
function DEBUG(){ function logdebug(){
local function_name="${funcname[1]}" local function_name="${funcname[1]}"
local msg="$1" local msg="$1"
timeAndDate=`date` timeAndDate=`date`
@ -91,7 +91,20 @@ function DEBUG(){
if [[ ! ${loglevels[*]} =~ "${LOGLEVEL-$MYHSELLCONFIG_LOGLEVEL_DEFAULT}" ]];then if [[ ! ${loglevels[*]} =~ "${LOGLEVEL-$MYHSELLCONFIG_LOGLEVEL_DEFAULT}" ]];then
echo $msg >&2 echo $msg >&2
fi fi
echo "[$timeAndDate] [DEBUG] $msg" >> $SCRIPT_LOG echo "[$timeAndDate] [DEBUG] $msg" >> $SCRIPT_LOG
}
function logtrace(){
local function_name="${funcname[1]}"
local msg="$1"
timeAndDate=`date`
local loglevels
declare -a loglevels
loglevels=("ERROR" "WARN" "INFO" "DEBUG")
if [[ ! ${loglevels[*]} =~ "${LOGLEVEL-$MYHSELLCONFIG_LOGLEVEL_DEFAULT}" ]];then
echo $msg >&2
fi
echo "[$timeAndDate] [TRACE] $msg" >> $SCRIPT_LOG
} }
@ -145,7 +158,7 @@ EOF
return 1 return 1
fi fi
else else
INFO "no sync allowed from config" >&2 logwarn "no sync allowed from config" >&2
return 0 return 0
fi fi
@ -168,10 +181,10 @@ EOF
[ -z "$nok" ] && mkdir -pv "${MYSHELLCONFIG_LOGDIR}" [ -z "$nok" ] && mkdir -pv "${MYSHELLCONFIG_LOGDIR}"
else else
echo "git not installed, no configuration possible, please install git" >&2 logwarn "git not installed, no configuration possible, please install git" >&2
fi fi
else else
INFO "Not syncing profile in case of configuration" logwarn "Not syncing profile in case of configuration"
fi fi
} }
@ -185,7 +198,7 @@ EOF
. "${XDG_CONFIG_HOME:-$HOME/.config}/bash_completion" . "${XDG_CONFIG_HOME:-$HOME/.config}/bash_completion"
if shopt -q progcomp && [ -r /usr/share/bash-completion/bash_completion ]; then if shopt -q progcomp && [ -r /usr/share/bash-completion/bash_completion ]; then
# Source completion code. # Source completion code.
echo "Source bash-completion" logdebug "Source bash-completion"
. /usr/share/bash-completion/bash_completion . /usr/share/bash-completion/bash_completion
fi fi
fi fi
@ -207,7 +220,7 @@ EOF
--8<--- end ---------------- $(date) ---------------8<-- --8<--- end ---------------- $(date) ---------------8<--
EOF EOF
#else else
# echo "non-interactive shell" >&2 logtrace "non-interactive shell" >&2
fi fi