improve logging
* add function to logoutput
This commit is contained in:
parent
8b29d607e4
commit
658b3f4bf6
1 changed files with 30 additions and 30 deletions
60
logging
60
logging
|
@ -10,11 +10,11 @@ function SCRIPTENTRY(){
|
|||
local loglevels
|
||||
declare -a loglevels
|
||||
loglevels=("ERROR" "WARN" "INFO")
|
||||
if [[ ! ${loglevels[*]} =~ "${LOGLEVEL-$LOGLEVEL_DEFAULT}" ]];then
|
||||
if [[ ! ${loglevels[*]} =~ "${LOGLEVEL:-$LOGLEVEL_DEFAULT}" ]];then
|
||||
timeAndDate=`date`
|
||||
script_name=`basename -- "$0"`
|
||||
script_name="${script_name%.*}"
|
||||
echo "[$timeAndDate] [DEBUG] > $script_name $FUNCNAME" >> $SCRIPT_LOG
|
||||
echo "[$timeAndDate] [SCRIPTENTRY] > $script_name $FUNCNAME" >> $SCRIPT_LOG
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -22,10 +22,10 @@ function SCRIPTEXIT(){
|
|||
local loglevels
|
||||
declare -a loglevels
|
||||
loglevels=("ERROR" "WARN" "INFO")
|
||||
if [[ ! ${loglevels[*]} =~ "${LOGLEVEL-$LOGLEVEL_DEFAULT}" ]];then
|
||||
if [[ ! ${loglevels[*]} =~ "${LOGLEVEL:-$LOGLEVEL_DEFAULT}" ]];then
|
||||
script_name=`basename -- "$0"`
|
||||
script_name="${script_name%.*}"
|
||||
echo "[$timeAndDate] [DEBUG] < $script_name $FUNCNAME" >> $SCRIPT_LOG
|
||||
echo "[$timeAndDate] [SCRIPTEXIT] < $script_name $FUNCNAME" >> $SCRIPT_LOG
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -33,10 +33,10 @@ function ENTRY(){
|
|||
local loglevels
|
||||
declare -a loglevels
|
||||
loglevels=("ERROR" "WARN" "INFO")
|
||||
if [[ ! ${loglevels[*]} =~ "${LOGLEVEL-$LOGLEVEL_DEFAULT}" ]];then
|
||||
if [[ ! ${loglevels[*]} =~ "${LOGLEVEL:-$LOGLEVEL_DEFAULT}" ]];then
|
||||
local cfn="${FUNCNAME[1]}"
|
||||
timeAndDate=`date`
|
||||
echo "[$timeAndDate] [DEBUG] > $cfn $FUNCNAME" >> $SCRIPT_LOG
|
||||
echo "[$timeAndDate] [ENTRY] > $cfn $FUNCNAME" >> $SCRIPT_LOG
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -44,10 +44,10 @@ function EXIT(){
|
|||
local loglevels
|
||||
declare -a loglevels
|
||||
loglevels=("ERROR" "WARN" "INFO")
|
||||
if [[ ! ${loglevels[*]} =~ "${LOGLEVEL-$LOGLEVEL_DEFAULT}" ]];then
|
||||
if [[ ! ${loglevels[*]} =~ "${LOGLEVEL:-$LOGLEVEL_DEFAULT}" ]];then
|
||||
local cfn="${FUNCNAME[1]}"
|
||||
timeAndDate=`date`
|
||||
echo "[$timeAndDate] [DEBUG] < $cfn $FUNCNAME" >> $SCRIPT_LOG
|
||||
echo "[$timeAndDate] [EXIT] < $cfn $FUNCNAME" >> $SCRIPT_LOG
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -65,11 +65,11 @@ function logerror(){
|
|||
local loglevels
|
||||
declare -a loglevels
|
||||
loglevels=()
|
||||
if [[ ! ${loglevels[*]} =~ "${LOGLEVEL-$LOGLEVEL_DEFAULT}" ]];then
|
||||
echo $opts "$msg" >&2
|
||||
if [[ ! ${loglevels[*]} =~ "${LOGLEVEL:-$LOGLEVEL_DEFAULT}" ]];then
|
||||
echo $opts "[ERROR] (${FUNCNAME[1]}) $msg" >&2
|
||||
fi
|
||||
if [[ ! ${loglevels[*]} =~ "${FILELOGLEVEL-$FILELOGLEVEL_DEFAULT}" ]];then
|
||||
echo "[$timeAndDate] [ERROR] $msg" >> $SCRIPT_LOG
|
||||
if [[ ! ${loglevels[*]} =~ "${FILELOGLEVEL:-$FILELOGLEVEL_DEFAULT}" ]];then
|
||||
echo "[$timeAndDate] [ERROR] (${FUNCNAME[1]}) $msg" >> $SCRIPT_LOG
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -87,11 +87,11 @@ function logwarn(){
|
|||
local loglevels
|
||||
declare -a loglevels
|
||||
loglevels=("ERROR" )
|
||||
if [[ ! ${loglevels[*]} =~ "${LOGLEVEL-$LOGLEVEL_DEFAULT}" ]];then
|
||||
echo $opts "$msg" >&2
|
||||
if [[ ! ${loglevels[*]} =~ "${LOGLEVEL:-$LOGLEVEL_DEFAULT}" ]];then
|
||||
echo $opts "[WARN] (${FUNCNAME[1]}) $msg" >&2
|
||||
fi
|
||||
if [[ ! ${loglevels[*]} =~ "${FILELOGLEVEL-$FILELOGLEVEL_DEFAULT}" ]];then
|
||||
echo "[$timeAndDate] [WARN] $msg" >> $SCRIPT_LOG
|
||||
if [[ ! ${loglevels[*]} =~ "${FILELOGLEVEL:-$FILELOGLEVEL_DEFAULT}" ]];then
|
||||
echo "[$timeAndDate] [WARN] (${FUNCNAME[1]}) $msg" >> $SCRIPT_LOG
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -109,17 +109,17 @@ function loginfo(){
|
|||
local loglevels
|
||||
declare -a loglevels
|
||||
loglevels=("ERROR" "WARN" )
|
||||
if [[ ! ${loglevels[*]} =~ "${LOGLEVEL-$LOGLEVEL_DEFAULT}" ]];then
|
||||
echo $opts "$msg" >&2
|
||||
if [[ ! ${loglevels[*]} =~ "${LOGLEVEL:-$LOGLEVEL_DEFAULT}" ]];then
|
||||
echo $opts "[INFO] (${FUNCNAME[1]}) $msg" >&2
|
||||
fi
|
||||
if [[ ! ${loglevels[*]} =~ "${FILELOGLEVEL-$FILELOGLEVEL_DEFAULT}" ]];then
|
||||
echo "[$timeAndDate] [INFO] $msg" >> $SCRIPT_LOG
|
||||
if [[ ! ${loglevels[*]} =~ "${FILELOGLEVEL:-$FILELOGLEVEL_DEFAULT}" ]];then
|
||||
echo "[$timeAndDate] [INFO] (${FUNCNAME[1]}) $msg" >> $SCRIPT_LOG
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
function logdebug(){
|
||||
local function_name="${funcname[1]}"
|
||||
local function_name="${FUNCNAME[1]}"
|
||||
case $1 in
|
||||
-n)
|
||||
local opts="-n"
|
||||
|
@ -132,16 +132,16 @@ function logdebug(){
|
|||
local loglevels
|
||||
declare -a loglevels
|
||||
loglevels=("ERROR" "WARN" "INFO")
|
||||
if [[ ! ${loglevels[*]} =~ "${LOGLEVEL-$LOGLEVEL_DEFAULT}" ]];then
|
||||
echo $opts "$msg" >&2
|
||||
if [[ ! ${loglevels[*]} =~ "${LOGLEVEL:-$LOGLEVEL_DEFAULT}" ]];then
|
||||
echo $opts "[DEBUG] (${FUNCNAME[1]}) $msg" >&2
|
||||
fi
|
||||
if [[ ! ${loglevels[*]} =~ "${FILELOGLEVEL-$FILELOGLEVEL_DEFAULT}" ]];then
|
||||
echo "[$timeAndDate] [DEBUG] $msg" >> $SCRIPT_LOG
|
||||
if [[ ! ${loglevels[*]} =~ "${FILELOGLEVEL:-$FILELOGLEVEL_DEFAULT}" ]];then
|
||||
echo "[$timeAndDate] [DEBUG] (${FUNCNAME[1]}) $msg" >> $SCRIPT_LOG
|
||||
fi
|
||||
}
|
||||
|
||||
function logtrace(){
|
||||
local function_name="${funcname[1]}"
|
||||
local function_name="${FUNCNAME[1]}"
|
||||
case $1 in
|
||||
-n)
|
||||
local opts="-n"
|
||||
|
@ -154,11 +154,11 @@ function logtrace(){
|
|||
local loglevels
|
||||
declare -a loglevels
|
||||
loglevels=("ERROR" "WARN" "INFO" "DEBUG")
|
||||
if [[ ! ${loglevels[*]} =~ "${LOGLEVEL-$LOGLEVEL_DEFAULT}" ]];then
|
||||
echo $opts "$msg" >&2
|
||||
if [[ ! ${loglevels[*]} =~ "${LOGLEVEL:-$LOGLEVEL_DEFAULT}" ]];then
|
||||
echo $opts "[TRACE] (${FUNCNAME[1]}) $msg" >&2
|
||||
fi
|
||||
if [[ ! ${loglevels[*]} =~ "${FILELOGLEVEL-$FILELOGLEVEL_DEFAULT}" ]];then
|
||||
echo "[$timeAndDate] [TRACE] $msg" >> $SCRIPT_LOG
|
||||
if [[ ! ${loglevels[*]} =~ "${FILELOGLEVEL:-$FILELOGLEVEL_DEFAULT}" ]];then
|
||||
echo "[$timeAndDate] [TRACE] (${FUNCNAME[1]}) $msg" >> $SCRIPT_LOG
|
||||
fi
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue