diff --git a/bashrc_add b/bashrc_add index 2753a55..7f514ed 100755 --- a/bashrc_add +++ b/bashrc_add @@ -93,22 +93,22 @@ EOF if [ $(stat --printf %Y ${MSC_GIT_UPD_REPO_STATFILE} 2>/dev/null || echo 0 ) \ -lt $(date --date="${MSC_GIT_REPO_UPDATE_INTERVALL-${MSC_GIT_REPO_UPDATE_INTERVALL_DEFAULT}} hours ago" "+%s") ]; then - logwarn "sync-intervall (${MSC_GIT_REPO_UPDATE_INTERVALL-${MSC_GIT_REPO_UPDATE_INTERVALL_DEFAULT}} hours) reached" - logwarn "check if reachable" + logwarning "sync-intervall (${MSC_GIT_REPO_UPDATE_INTERVALL-${MSC_GIT_REPO_UPDATE_INTERVALL_DEFAULT}} hours) reached" + logwarning "check if reachable" if $( timeout --foreground "${MSC_GIT_TIMEOUT-$MSC_GIT_TIMEOUT_DEFAULT}" $SGIT ls-remote >/dev/null 2>&1) ;then - logwarn "reachable" + logwarning "reachable" return 0 else - logwarn "not reachable" + logwarning "not reachable" return 3 fi else local seconds=$(( $( date --date="@$(stat --printf %Y ${MSC_GIT_UPD_REPO_STATFILE} 2>/dev/null || echo 0 )" "+%s") - $(date --date="${MSC_GIT_REPO_UPDATE_INTERVALL-${MSC_GIT_REPO_UPDATE_INTERVALL_DEFAULT}} hours ago" "+%s") )) - logwarn "repo sync-intervall (${MSC_GIT_REPO_UPDATE_INTERVALL-${MSC_GIT_REPO_UPDATE_INTERVALL_DEFAULT}} hours) not reached yet. $((seconds/86400)) days $(date -d "1970-01-01 + $seconds seconds" "+%H hours %M minutes %S seconds") left." + logwarning "repo sync-intervall (${MSC_GIT_REPO_UPDATE_INTERVALL-${MSC_GIT_REPO_UPDATE_INTERVALL_DEFAULT}} hours) not reached yet. $((seconds/86400)) days $(date -d "1970-01-01 + $seconds seconds" "+%H hours %M minutes %S seconds") left." return 2 fi else - logwarn "no sync allowed from config" >&2 + logwarning "no sync allowed from config" >&2 return 1 fi @@ -136,10 +136,10 @@ EOF [ -z "$nok" ] && mkdir -pv "${MSC_LOGDIR}" else - logwarn "git not installed, no configuration possible, please install git" >&2 + logwarning "git not installed, no configuration possible, please install git" >&2 fi else - logwarn "Not syncing profile in case of configuration" + logwarning "Not syncing profile in case of configuration" fi } diff --git a/bin/exif-fixdatetime b/bin/exif-fixdatetime index 6a9f25f..20c02ba 100755 --- a/bin/exif-fixdatetime +++ b/bin/exif-fixdatetime @@ -164,7 +164,7 @@ run_fix () { MIMEDEST="${mimedestvid}/${subdestvid}" ;; *) - logwarn "unsupportet mimetype »${mime}« for »${file}«" + logwarning "unsupportet mimetype »${mime}« for »${file}«" ;; esac if [ -n "${MIMEDEST+x}" ] ; then @@ -179,7 +179,7 @@ run_fix () { $setoriginalfilename && exiftool -overwrite_original "-originalfilename&1 |tee -a ${LOGFILE})" - logwarn "$(readlink -f "$file"): $(exiftool -filename -if '(not ($datetimeoriginal or $createdate))' "$file")" + logwarning "$(readlink -f "$file"): $(exiftool -filename -if '(not ($datetimeoriginal or $createdate))' "$file")" else loginfo "$(exiftool -o . '-Directory&1 |tee -a ${LOGFILE})" - logwarn "$(readlink -f "$file"): $(exiftool -filename -if '(not ($datetimeoriginal or $createdate))' "$file")" + logwarning "$(readlink -f "$file"): $(exiftool -filename -if '(not ($datetimeoriginal or $createdate))' "$file")" fi ;; renameinplace) @@ -279,7 +279,7 @@ run_fix () { fi ;; *) - logwarn "value for move is neither »true« nor »copy«" + logwarning "value for move is neither »true« nor »copy«" esac fi diff --git a/bin/git-myshellconfig-checkout b/bin/git-myshellconfig-checkout index 15593b3..fec633d 100755 --- a/bin/git-myshellconfig-checkout +++ b/bin/git-myshellconfig-checkout @@ -91,8 +91,8 @@ fi #echo $SGIT fetch ${MSC_GIT_REMOTE_NAME} -p 1>&2 if $dorepoupdate; then loginfo "fetch repo${dosubmodupdate:+ and submodules}" - #$SGIT fetch ${dosubmodupdate:+--recurse-submodules} ${MSC_GIT_REMOTE_NAME} -p 2>>"${MSC_LOGFILE}"|| { logwarn fetch failed; gitupdateend; exit 1; } - $SGIT fetch ${dosubmodupdate:+--recurse-submodules} ${MSC_GIT_REMOTE_NAME} -p 2>>"${MSC_LOGFILE}"|| { logwarn fetch failed; gitupdateend; exit 1; } + #$SGIT fetch ${dosubmodupdate:+--recurse-submodules} ${MSC_GIT_REMOTE_NAME} -p 2>>"${MSC_LOGFILE}"|| { logwarning fetch failed; gitupdateend; exit 1; } + $SGIT fetch ${dosubmodupdate:+--recurse-submodules} ${MSC_GIT_REMOTE_NAME} -p 2>>"${MSC_LOGFILE}"|| { logwarning fetch failed; gitupdateend; exit 1; } if ${dosubmodupdate:-false}; then lastupdatesubmodules fi @@ -107,7 +107,7 @@ EOF $SGIT merge FETCH_HEAD 1>>"${MSC_LOGFILE}" 2>>"${MSC_LOGFILE}"|| { gitupdateend; exit 3; } touch $MSC_GIT_UPD_REPO_STATFILE else - logwarn -n " Lokale Änderungen festgestellt:" + logwarning -n " Lokale Änderungen festgestellt:" echo " Siehe Logfile ${MSC_LOGFILE}" >&2 cat << EOF >> "${MSC_LOGFILE}" um die Änderung zurückzusetzen bitte @@ -137,7 +137,7 @@ EOF logdebug "$($SGIT submodule update --remote)" logdebug "$($SGIT commit -a -m 'update submodules')" touch $MSC_GIT_UPD_SUBMOD_STATFILE - logwarn "submodules synced" + logwarning "submodules synced" fi fi diff --git a/bin/haproxy-maintenance b/bin/haproxy-maintenance index 7e508da..b770058 100755 --- a/bin/haproxy-maintenance +++ b/bin/haproxy-maintenance @@ -93,6 +93,7 @@ EOF while [ $i -lt ${#BACKENDS[@]} ];do cat << EOF +==================================================== Action: $ACTION Umgebung: $UMG Cluster: $CLUSTER diff --git a/bin/lastlocallogins b/bin/lastlocallogins deleted file mode 100755 index ecec804..0000000 --- a/bin/lastlocallogins +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh - -F="$(for i in $(find /var/log -maxdepth 1 -name "wtmp*"|sort -h);do echo -n "-f $i ";done)" -cat << EOF ------ -Alle Tage mit lokalen Logins -User: ${1:-$USER} -Host: $(hostname) -Files: $F ------ - -EOF -last -w -F -a $F |grep -v "pts/\|reboot\|wtmp"|awk '$1 == u {print $4,$5,$7}' u=${1:-$USER}|uniq diff --git a/bin/startagent b/bin/startagent index 84b4f6c..2469391 100755 --- a/bin/startagent +++ b/bin/startagent @@ -3,7 +3,7 @@ FILELOGLEVEL=DEBUG # loggerfactory LANG=C -for f in logerror logwarn loginfo logdebug logtrace ENTRY EXIT SCRIPTENTRY SCRIPTEXIT; do +for f in logerror logwarning loginfo logdebug logtrace ENTRY EXIT SCRIPTENTRY SCRIPTEXIT; do if LANG=C type -t $f 2> /dev/null| grep -q 'function'; then : else @@ -198,7 +198,7 @@ agent-start-or-restart () { ;; 1) logdebug "agent is running, but:" - logwarn "$msg" + logwarning "$msg" ;; 2) logdebug "former agent is not running -> start it" @@ -222,7 +222,7 @@ $(ssh-runinagent $agentfile ssh-add -l)" echo $agentfile ret=0 else - logwarn "ssh-identity »$ssh_identity« is not configured. Please create $identitydir and add keys" + logwarning "ssh-identity »$ssh_identity« is not configured. Please create $identitydir and add keys" ret=2 fi @@ -240,7 +240,7 @@ $(ssh-runinagent $agentfile ssh-add -l)" echo $agentfile ret=0 else - logwarn "no identity given -> exit" + logwarning "no identity given -> exit" ret=1 fi @@ -318,15 +318,15 @@ agent-load-identity-keys () { pubkeysonly+=($pubkey) fi if [ -e "${pubkey%.pub}-cert.pub" ]; then - #logwarn "${pubkey%.pub}-cert.pub: $(date +%s -d $(ssh-keygen -L -f "${pubkey%.pub}-cert.pub"|awk '$1 == "Valid:"{print $5}'))" - #logwarn "now: $(date +%s -d NOW)" + #logwarning "${pubkey%.pub}-cert.pub: $(date +%s -d $(ssh-keygen -L -f "${pubkey%.pub}-cert.pub"|awk '$1 == "Valid:"{print $5}'))" + #logwarning "now: $(date +%s -d NOW)" cert_exp_date=$(ssh-keygen -L -f "${pubkey%.pub}-cert.pub"|awk '$1 == "Valid:"{print $5}') #[ $(date +%s -d $(ssh-keygen -L -f "${pubkey%.pub}-cert.pub"|awk '$1 == "Valid:"{print $5}')) -gt $(date +%s -d NOW) ] \ [ $(date +%s -d $cert_exp_date) -gt $(date +%s -d NOW) ] \ - || logwarn "CERTIFICATE IS NOT VALID ANYMORE: ${pubkey%.pub}-cert.pub" + || logwarning "CERTIFICATE IS NOT VALID ANYMORE: ${pubkey%.pub}-cert.pub" #[ $(date +%s -d $(ssh-keygen -L -f "${pubkey%.pub}-cert.pub"|awk '$1 == "Valid:"{print $5}')) -lt $(date +%s -d "$SSH_CERT_VALIDITY_WARN_SEC") ] \ [ $(date +%s -d $cert_exp_date) -lt $(date +%s -d "$SSH_CERT_VALIDITY_WARN_SEC") ] \ - && logwarn "CERTIFICATE expires in $(echo "scale=0; ( `date -d $cert_exp_date +%s` - `date -d now +%s`) / (24*3600)" | bc -l) days: ${pubkey%.pub}-cert.pub" + && logwarning "CERTIFICATE expires in $(echo "scale=0; ( `date -d $cert_exp_date +%s` - `date -d now +%s`) / (24*3600)" | bc -l) days: ${pubkey%.pub}-cert.pub" fi done loginfo "pubkeysonly: ${pubkeysonly[@]} (count: ${#pubkeysonly[*]})" @@ -364,7 +364,7 @@ agent-load-identity-keys () { loginfo "currently loaded keys after action: $(ssh-runinagent $agentfile ssh-add -l|wc -l)" logdebug "$(ssh-runinagent $agentfile ssh-add -l)" else - logwarn "ssh-identity $ssh_identity is not configured. Please create $identitydir and add keys" + logwarning "ssh-identity $ssh_identity is not configured. Please create $identitydir and add keys" fi fi @@ -380,12 +380,12 @@ function check-pubkeysonly () { ssh-runinagent $agentfile ssh-add -T ${p} 2>&1 || { $remove || readd=true; break; } done else - logwarn "obviously there is no pubkey for the token in ${SSH_IDENTITIES_DIR}/${ssh_identity}/" - logwarn "you can add the pubkey with" - logwarn " ssh-add -L > ${SSH_IDENTITIES_DIR}/${ssh_identity}/id_etoken.pub" - logwarn "make sure, only the token is loaded into ssh-agent with" - logwarn " ssh-add -l" - logwarn "only one line should be the output" + logwarning "obviously there is no pubkey for the token in ${SSH_IDENTITIES_DIR}/${ssh_identity}/" + logwarning "you can add the pubkey with" + logwarning " ssh-add -L > ${SSH_IDENTITIES_DIR}/${ssh_identity}/id_etoken.pub" + logwarning "make sure, only the token is loaded into ssh-agent with" + logwarning " ssh-add -l" + logwarning "only one line should be the output" fi logdebug "readd: $readd" } @@ -405,7 +405,7 @@ ssh-runinagent () { /bin/sh -c "unset SSH_AUTH_SOCK SSH_AGENT_PID; . $agentfile >/dev/null 2>/dev/null; $sshcommand" ret=$? else - logwarn "agentfile not existent" + logwarning "agentfile not existent" ret=99 fi diff --git a/bin/testlog b/bin/testlog index 24a9c89..c74b1a7 100755 --- a/bin/testlog +++ b/bin/testlog @@ -1,7 +1,7 @@ #!/bin/bash LANG=C -for f in logerror logwarn loginfo logdebug logtrace ENTRY EXIT SCRIPTENTRY SCRIPTEXIT; do +for f in logerror logwarning loginfo logdebug logtrace ENTRY EXIT SCRIPTENTRY SCRIPTEXIT; do if LANG=C type -t $f 2> /dev/null| grep -q 'function'; then : else @@ -37,7 +37,7 @@ done unset f logerror "ich bin ein error" -logwarn "ich bin eine warnung" +logwarning "ich bin eine warnung" loginfo "ich bin eine info" logdebug "ich bin eine debuginfo" logtrace "ich rede zuviel" diff --git a/functions.sh b/functions.sh index a16e95e..5fe31f6 100755 --- a/functions.sh +++ b/functions.sh @@ -99,12 +99,12 @@ setproxy () { local CONFIG case $# in 0) - logwarn "too few arguments" + logwarning "too few arguments" return ;; *) if [ -z ${SETPROXY_CREDS_DIRS+x} ] ; then - logwarn "are you sure, SETPROXY_CREDS_DIRS is defined?" + logwarning "are you sure, SETPROXY_CREDS_DIRS is defined?" return 1 else CONFIG=$(find ${SETPROXY_CREDS_DIRS[*]} -mindepth 1 -name "$1.conf" -print -quit 2>/dev/null ) @@ -113,7 +113,7 @@ setproxy () { ;; esac - logwarn "CONFIG: ${CONFIG}" + logwarning "CONFIG: ${CONFIG}" if [ -e ${CONFIG} ]; then logdebug -n "${CONFIG} existing: " @@ -165,7 +165,7 @@ unsetproxy () { mencfs () { ENTRY - [ $# -eq 0 ] && { logwarn "too few arguments" >&2; return 1; } + [ $# -eq 0 ] && { logwarning "too few arguments" >&2; return 1; } local PKEY local ENCDIR local DESTDIR @@ -173,7 +173,7 @@ mencfs () { local ENCFS=$(which encfs 2>/dev/null || exit 127 ) local CONFIG if [ -z ${ENCFS_CONFIG_DIRS+x} ] ; then - logwarn "are you sure, ENCFS_CONFIG_DIRS is defined?" + logwarning "are you sure, ENCFS_CONFIG_DIRS is defined?" EXIT return 1 else @@ -225,7 +225,7 @@ uencfs () { [ -z ${FUSERMOUNT+x} ] && return 127 if [ $# -eq 1 ]; then if [ ! -d ${1} ];then - logwarn "encrypted directory ${1} not found -> exit" >&2 + logwarning "encrypted directory ${1} not found -> exit" >&2 EXIT return 128 else @@ -255,7 +255,7 @@ kinit-custom () { local KINIT=$(which kinit 2>/dev/null || exit 127 ) local CONFIG if [ -z ${KERBEROS_CONFIG_DIRS+x} ] ; then - logwarn "are you sure, KERBEROS_CONFIG_DIRS is defined?" + logwarning "are you sure, KERBEROS_CONFIG_DIRS is defined?" EXIT return 1 else @@ -267,7 +267,7 @@ kinit-custom () { source "${CONFIG}" logdebug "sourced" else - logwarn "${CONFIG} not existing" + logwarning "${CONFIG} not existing" EXIT return 2 fi @@ -283,7 +283,7 @@ kinit-custom () { loginfo "Get kerberos-ticket for: $KERBEROS_USER@$REALM" if [ -z ${KERBEROS_USER:+x} ];then - logwarn "no kerberos user found -> exit" + logwarning "no kerberos user found -> exit" EXIT return 4 else @@ -496,11 +496,11 @@ EOF # ssh -t ${SSH_OPTS} $@ "$RCMD; SSHS=true bash -c \"function bash () { /bin/bash --rcfile ${REMOTETMPCONFIGS[0]} -i ; } ; export -f bash; exec bash --rcfile ${REMOTETMPCONFIGS[0]}\"" # rm "${TMPBASHCONFIG}" # else -# logwarn "${TMPBASHCONFIG} does not exist. Using »ssh -t $@«" +# logwarning "${TMPBASHCONFIG} does not exist. Using »ssh -t $@«" # ssh -t "$@" # fi # else -# logwarn "too few arguments for sshs" >&2 +# logwarning "too few arguments for sshs" >&2 # ssh # fi # @@ -654,7 +654,7 @@ function tmuxx() { SESS=($(find ${TMUX_SESSION_DIRS[*]} -mindepth 1 -name "$1.session" 2>/dev/null )) ;; *) - logwarn no session specified return + logwarning no session specified return ;; esac TMUX_BIN='/usr/bin/tmux' @@ -691,7 +691,7 @@ EOF which pdsh 1>/dev/null 2>&1 && pdsh -g vpn sudo systemctl status backup.service else - logwarn "backup.vpn is not reachable -> exit" + logwarning "backup.vpn is not reachable -> exit" return 1 fi @@ -718,7 +718,7 @@ changebeep() { style=audible ;; *) - logwarn "usage: changebeep [none|visible|audible]" + logwarning "usage: changebeep [none|visible|audible]" EXIT return 1 ;; @@ -847,7 +847,7 @@ reachable () { loginfo -n "Try to resolve $SERVER: " local IP=$(getent $GETENTHOSTS $SERVER|awk '$0 ~ /STREAM/ {print $1}'|uniq|head -n1) if [ -z ${IP-x} ]; then - logwarn "not resolvable -> exit" + logwarning "not resolvable -> exit" return 1 else loginfo $IP diff --git a/logging b/logging index 29f1900..1dcd13a 100644 --- a/logging +++ b/logging @@ -6,168 +6,45 @@ mkdir -p "$(dirname ${SCRIPT_LOG})" touch $SCRIPT_LOG -function SCRIPTENTRY(){ - local loglevels - declare -a loglevels - loglevels=("ERROR" "WARN" "INFO") - if [[ ! ${loglevels[*]} =~ "${LOGLEVEL:-$LOGLEVEL_DEFAULT}" ]];then - timeAndDate=`date` - script_name=`basename -- "$0"` - script_name="${script_name%.*}" - echo "[$timeAndDate] [SCRIPTENTRY] > $script_name $FUNCNAME" >> $SCRIPT_LOG - fi -} +#for level in emerg alert crit err warning notice info debug; do -function SCRIPTEXIT(){ - local loglevels - declare -a loglevels - loglevels=("ERROR" "WARN" "INFO") - if [[ ! ${loglevels[*]} =~ "${LOGLEVEL:-$LOGLEVEL_DEFAULT}" ]];then - script_name=`basename -- "$0"` - script_name="${script_name%.*}" - echo "[$timeAndDate] [SCRIPTEXIT] < $script_name $FUNCNAME" >> $SCRIPT_LOG - fi -} +loglevels=(debug info notice warning err crit alert emerg) -function ENTRY(){ +for level in SCRIPTENTRY SCRIPTEXIT ENTRY EXIT; do + printf -v functext -- '%s() { local loglevels declare -a loglevels - loglevels=("ERROR" "WARN" "INFO") - if [[ ! ${loglevels[*]} =~ "${LOGLEVEL:-$LOGLEVEL_DEFAULT}" ]];then - local cfn="${FUNCNAME[1]}" - timeAndDate=`date` - echo "[$timeAndDate] [ENTRY] > $cfn $FUNCNAME" >> $SCRIPT_LOG - fi -} - -function EXIT(){ - local loglevels - declare -a loglevels - loglevels=("ERROR" "WARN" "INFO") - if [[ ! ${loglevels[*]} =~ "${LOGLEVEL:-$LOGLEVEL_DEFAULT}" ]];then - local cfn="${FUNCNAME[1]}" - timeAndDate=`date` - echo "[$timeAndDate] [EXIT] < $cfn $FUNCNAME" >> $SCRIPT_LOG - fi -} - -function logerror(){ - local function_name="${FUNCNAME[1]}" - case $1 in - -n) - local opts="-n" - shift - ;; - esac - local msg="$1" - [ -z "${msg:+x}" ] && return 0 - timeAndDate=`date` - local loglevels - declare -a loglevels - loglevels=() - if [[ ! ${loglevels[*]} =~ "${LOGLEVEL:-$LOGLEVEL_DEFAULT}" ]];then - echo $opts "[ERROR] (${FUNCNAME[1]}) $msg" >&2 + loglevels=(emerg alert crit err warning notice info) + timeAndDate=$(date) + script_name="${BASH_SOURCE[0]##*/}" + local LOGLEVEL=${LOGLEVEL,,} + if [[ ! ${loglevels[@]} =~ "${LOGLEVEL:-${LOGLEVEL_DEFAULT,,}}" ]];then + echo "[%s] »${script_name}« ######################################################" >&2 fi if [[ ! ${loglevels[*]} =~ "${FILELOGLEVEL:-$FILELOGLEVEL_DEFAULT}" ]];then - echo "[$timeAndDate] [ERROR] (${FUNCNAME[1]}) $msg" >> $SCRIPT_LOG - fi -} + echo "[${timeAndDate}] [%s] ${script_name}" >> "${SCRIPT_LOG}" + fi }' "${level}" "${level^^}" "${level^^}" + eval "$functext" + export -f "${level}" +done -function logwarn(){ - local function_name="${FUNCNAME[1]}" - case $1 in - -n) - local opts="-n" - shift - ;; - esac - local msg="$1" +for level in trace debug info notice warning err crit alert emerg; do + loglevels=( ${loglevels[@]/$level} ) + printf -v functext -- 'log%s() { + local msg="$@" [ -z "${msg:+x}" ] && return 0 - timeAndDate=`date` local loglevels declare -a loglevels - loglevels=("ERROR" ) - if [[ ! ${loglevels[*]} =~ "${LOGLEVEL:-$LOGLEVEL_DEFAULT}" ]];then - echo $opts "[WARN] (${FUNCNAME[1]}) $msg" >&2 + loglevels=(%s) + timeAndDate=$(date) + script_name="${BASH_SOURCE[0]##*/}" + local LOGLEVEL=${LOGLEVEL,,} + if [[ ! ${loglevels[@]} =~ "${LOGLEVEL:-${LOGLEVEL_DEFAULT,,}}" ]];then + printf "[%%s] (%%s) %%s\n" %s "${FUNCNAME[1]}" "${msg}" >&2 fi if [[ ! ${loglevels[*]} =~ "${FILELOGLEVEL:-$FILELOGLEVEL_DEFAULT}" ]];then - echo "[$timeAndDate] [WARN] (${FUNCNAME[1]}) $msg" >> $SCRIPT_LOG - fi -} - -function loginfo(){ - local function_name="${FUNCNAME[1]}" - case $1 in - -n) - local opts="-n" - shift - ;; - esac - local msg="$1" - [ -z "${msg:+x}" ] && return 0 - timeAndDate=`date` - local loglevels - declare -a loglevels - loglevels=("ERROR" "WARN" ) - if [[ ! ${loglevels[*]} =~ "${LOGLEVEL:-$LOGLEVEL_DEFAULT}" ]];then - echo $opts "[INFO] (${FUNCNAME[1]}) $msg" >&2 - fi - if [[ ! ${loglevels[*]} =~ "${FILELOGLEVEL:-$FILELOGLEVEL_DEFAULT}" ]];then - echo "[$timeAndDate] [INFO] (${FUNCNAME[1]}) $msg" >> $SCRIPT_LOG - fi -} - - -function logdebug(){ - local function_name="${FUNCNAME[1]}" - case $1 in - -n) - local opts="-n" - shift - ;; - esac - local msg="$1" - [ -z "${msg:+x}" ] && return 0 - timeAndDate=`date` - local loglevels - declare -a loglevels - loglevels=("ERROR" "WARN" "INFO") - if [[ ! ${loglevels[*]} =~ "${LOGLEVEL:-$LOGLEVEL_DEFAULT}" ]];then - echo $opts "[DEBUG] (${FUNCNAME[1]}) $msg" >&2 - fi - if [[ ! ${loglevels[*]} =~ "${FILELOGLEVEL:-$FILELOGLEVEL_DEFAULT}" ]];then - echo "[$timeAndDate] [DEBUG] (${FUNCNAME[1]}) $msg" >> $SCRIPT_LOG - fi -} - -function logtrace(){ - local function_name="${FUNCNAME[1]}" - case $1 in - -n) - local opts="-n" - shift - ;; - esac - local msg="$1" - [ -z "${msg:+x}" ] && return 0 - timeAndDate=`date` - local loglevels - declare -a loglevels - loglevels=("ERROR" "WARN" "INFO" "DEBUG") - if [[ ! ${loglevels[*]} =~ "${LOGLEVEL:-$LOGLEVEL_DEFAULT}" ]];then - echo $opts "[TRACE] (${FUNCNAME[1]}) $msg" >&2 - fi - if [[ ! ${loglevels[*]} =~ "${FILELOGLEVEL:-$FILELOGLEVEL_DEFAULT}" ]];then - echo "[$timeAndDate] [TRACE] (${FUNCNAME[1]}) $msg" >> $SCRIPT_LOG - fi -} - -export -f logerror -export -f logwarn -export -f loginfo -export -f logdebug -export -f logtrace -export -f SCRIPTENTRY -export -f ENTRY -export -f SCRIPTEXIT -export -f EXIT + printf "[%%s] [%%s] (%%s) %%s\n" "$timeAndDate" %s "${FUNCNAME[1]}" "${msg}" >> "${SCRIPT_LOG}" + fi }' "$level" "$(echo ${loglevels[@]})" "${level^^}" "${level^^}" + eval "$functext" + export -f "log${level}" +done