Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DEBUG_LOG="${0##*/}.log"
- # copy stdout to log always and echo to console
- exec > >(tee -a ${DEBUG_LOG})
- # copy stderr to log only, unless debugging is enabled
- [ $DEBUG_TEST = "true" ]
- && exec 2> >(tee -a ${DEBUG_LOG} >&2)
- || exec 2>> ${DEBUG_LOG}
- # Expand escaped characters, wrap at 70 chars on spaces,
- # and indent wrapped lines
- msg_log() {
- echo -e "$(date +%T) ${0##*/}: $1"
- | fold -w70 -s | sed '2~1s/^/ /' >&2;
- }
- msg_con() {
- if [ "${DEBUG_TEST}" = "true" ]; then
- msg_log "$1"
- else
- echo -e "$1" | fold -w70 -s | sed '2~1s/^/ /';
- fi
- }
- function startLogging {
- exec > >(gawk -v pid=$$ '{ print strftime("%F-%T"),pid,$0; fflush(); }' | tee -a $logfile)
- [ ! -z "$DEBUG" ] && exec 2>&1 || exec 2> >(gawk -v pid=$$ '{ print strftime("%F-%T"),pid,$0; fflush(); }' >>$logfile)
- echo "=== Log started for $$ at $(date +%F-%T) ==="
- }
- exec 1>>${DEBUG_LOG}
- exec 2>>${DEBUG_LOG}
- ./my_script 1>>${DEBUG_LOG} 2>>${DEBUG_LOG}
- echo -n $(date) >> $DEBUG_LOG
- command 2>&1 | tee -a $DEBUG_LOG
- echo -n $(date) >> $DEBUG_LOG
- command >> $DEBUG_LOG 2>&1
Add Comment
Please, Sign In to add comment