2020-12-03 20:48:04 -08:00
|
|
|
#!/bin/bash
|
|
|
|
# TODO allow debug to have managment flags and levels
|
|
|
|
function debug () {
|
2023-02-22 11:39:34 -08:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2020-12-03 20:48:04 -08:00
|
|
|
}
|
|
|
|
|
2023-02-22 11:39:34 -08:00
|
|
|
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
|
|
|
|
|
|
|
|
}
|
2022-02-20 12:44:29 -08:00
|
|
|
|
|
|
|
|
2023-02-22 11:39:34 -08:00
|
|
|
## *************** DEBUGGING ***********************
|
2022-02-20 12:44:29 -08:00
|
|
|
# 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)
|
|
|
|
|
|
|
|
# *
|