shell-base/modules/scripting/debug.lib

62 lines
1.4 KiB
Bash

#!/bin/bash
# TODO allow debug to have managment flags and levels
function debug () {
if [[ $BASH_DEBUG ]]; then
if [[ $BASH_DEBUG == "stdout" ]]; then
echo -e "#### DEBUG ####\n $@ \n#####" >&2
else
local logfile=$BASH_SHELL_USER_DIR/logs/$BASH_DEBUG.log
[[ $1 == "-r" ]] && echo "$(date) Debugging log file, see debug.lib module" > $logfile && return
echo -e "$@" >&2 >> $logfile
fi
fi
# [[ $test ]] && return
}
function debug_reset () {
local logfile=$BASH_SHELL_USER_DIR/logs/$1.log
echo clearing $logfile
echo "$logfile at $(date)" > $logfile
shift
echo $@ >> $logfile
echo -e "#####################" >> $logfile
}
## *************** DEBUGGING ***********************
# module_load debug
# if [[ $? -ne 0 ]]; then
# echo "unable to load a 'debug' module using a noop for debug function"
# # noop
# function debug () {
# :
# }
# fi
# [[ ! $- == *i* ]] && exec >> ~/logs/load.log && exec 2>&1
# export BASH_DEBUG=true
# uncomment for debugging
# echo $USER running load script in $DIR
# echo callers
# caller
# echo $(ps -o comm= $PPID)
# echo -----
# echo $BASH_SHELL_DIRS
# ******************END DEBUGGING *******************************
# ***************** LOGGING *****************
# function nilog () {
# [[ ! $- == *i* ]] && echo -e "-----\n $USER $*" &>> ~/logs/load.log
# }
# nilog "called load.sh $(date)"
# nilog caller: $(caller)
# nilog pid: $(ps -o comm= $PPID)
# *