Shell 日志与打印输出

良好的 shell 脚本从记录日志内容,规范日志格式开始。

1

write_log()
{
    LOG_FILE=$LOGDIR/cckiller_$(date +%Y-%m-%d).log

    logout=""
    for((i=2;i<=$#;i++)); do 
        j=${!i}
        logout="${logout} $j "
    done

    if [[ $LOG_LEVEL == "INFO" ]] && [[ "$1" == "INFO" ]];then
        echo "[`date "+%Y-%m-%d %H:%M:%S"`][$1]: ${logout}" | tee -ai $LOG_FILE 

    elif [[ $LOG_LEVEL == "DEBUG" ]];then
        echo "[`date "+%Y-%m-%d %H:%M:%S"`][$1]: ${logout}" | tee -ai $LOG_FILE 

    else
        echo "[`date "+%Y-%m-%d %H:%M:%S"`][$1]: ${logout}"

    fi

}
Copyright © ghostwritten 浙ICP备2020032454号 2022 all right reserved,powered by Gitbook该文件修订时间: 2022-06-22 06:35:33

results matching ""

    No results matching ""