The following code is the basic concept of my log file in my bash script:
LOG=/tmp/BACKUP_PROCCESS.log
LOG_DISABLE=FALSE
MY_LOG ()
{
[ $LOG_DISABLE = TRUE ] && return
echo "[`date +%d"/"%b"/"%G"-"%T`] INFO $1" >> $LOG
}
MY_LOG "START TO BACKUP FILES UNDER /VAR/LOG"
This code helped me to understand or troubleshoot each step in my bash script, but sometimes I want to disable the log creation because we don't need them and I want to make the script more efficient (calling the log function on each line in the script takes time and makes the script more heavy).
So my question is:
What is the most elegant way to disable the log file?
Until now I've disabled the log function by returning inside it, but that solution was not great since I still call the function.
I have smart solution to disable the log file
example ,
unset -f MY_LOG
shopt -s expand_aliases
alias MY_LOG=true
the command unset disable the MY_LOG function
and I add alias MY_LOG to true command
the meaning of that is very time when MY_LOG will activate, actually it will activate the true command , and true command not really do anything