问题描述
亲爱的朋友们和学院
以下code,是我的日志文件的基本概念在我的bash脚本
这code帮助我理解我的bash脚本或者如果每一个步骤,我们需要做的故障排除
但有些时候我想禁用日志创建,因为我们并不需要的日志,并希望使剧本更加效率(调用日志功能在脚本的每一行需要时间,使脚本更重)
所以我的问题我的朋友们:
什么是最好的优雅的方式来禁用日志文件?
到现在为止我禁用了日志功能通过返回我的日志函数内部
但这种方法不太好,因为我还调用函数
LOG =的/ tmp / BACKUP_PROCCESS.log
LOG_DISABLE = FALSE
MY_LOG()
{
[$ LOG_DISABLE = TRUE]放大器;&安培;返回
回声[`日期+%D/%B/%G - %T`] INFO $ 1>> $ LOG
}
MY_LOG开始备份文件在/ var / LOG
我有聪明的解决方案,以禁用日志文件
例如:
取消设置-f MY_LOG
禁用了javascript -s expand_aliases
别名MY_LOG = TRUE
命令的取消设置禁用 MY_LOG 功能
和我添加别名 MY_LOG 为真正命令
那意思很时候的 MY_LOG 将激活,实际上它会激活真正命令和真正命令没有真正做什么
dear friends and colleges
the following code , is the basic concept of my log file in my bash script
this Code help me to understand each step in my bash script or in case we need to make troubleshooting
but some times I want to disable the Log creation because we not need the log and want to make the script more efficiency ( call to Log function each line in the script take time and make the script more heavy )
so my question my friends:
What the best elegant way to disable the log file?
Until now I disabled the log function by return inside my log function
But this solution not so good because I still call the function
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"
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
这篇关于庆典 - 最佳优雅的方式来禁用日志文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!