From daeb67a33495899af2bf703231e7165366d9f681 Mon Sep 17 00:00:00 2001 From: Darren 'Tadgy' Austin Date: Tue, 21 Sep 2021 19:36:56 +0100 Subject: [PATCH] Add debugging support. Bump version. --- lumberjack | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lumberjack b/lumberjack index dc54fff..d0c69ce 100755 --- a/lumberjack +++ b/lumberjack @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright (c) 2018-2020: +# Copyright (c) 2018-2021: # Darren 'Tadgy' Austin # Licensed under the terms of the GNU General Public License version 3. # @@ -8,7 +8,7 @@ # Script details. NAME="${0##*/}" -VERSION="0.3.1" +VERSION="0.3.2" # Functions. @@ -67,6 +67,7 @@ create_missing_dirs() { die() { # $1 The text of the error message to display on stderr. + (( DEBUG == 1 )) && printf "%s: %s: %s\\n" "$(date "+%Y%m%d %H%M%S.%N")" "die" "$1" >>"$DEBUG_FILE" printf "%s: %s\\n" "$NAME" "$1" >&2 exit 1 } @@ -314,6 +315,7 @@ syslog() { [[ -z "$1" || -z "$2" ]] && return 1 + (( DEBUG == 1 )) && printf "%s: %s: %s: %s\\n" "$(date "+%Y%m%d %H%M%S.%N")" "syslog" "$1" "$2" >>"$DEBUG_FILE" logger --id="$$" -p "$SYSLOG_FACILITY.$1" -t "$NAME" "$1: $2" 2>/dev/null } @@ -572,7 +574,7 @@ while :; do start_compression_jobs # If debugging is enabled, record the time of entry into the read below. - (( DEBUG == 1 )) && printf "%s - %s\n" "$(date "+%Y%m%d %H%M%S.%N")" "Enter read" >>"$DEBUG_FILE" + (( DEBUG == 1 )) && printf "%s: %s\\n" "$(date "+%Y%m%d %H%M%S.%N")" "enter read" >>"$DEBUG_FILE" # Read the log line, but timeout at the top of the next second if nothing is read. # Note: The second $(...) expansion should *not* be quoted in this instance, and @@ -582,7 +584,7 @@ while :; do ERR="$?" # If debugging, record the time of exit from read. - (( DEBUG == 1 )) && printf "%s - %s\n" "$(date "+%Y%m%d %H%M%S.%N")" "Exit read: ERR = $ERR, VHOST = $LOG_VHOST DATA = ${LOG_DATA:0:50}" >>"$DEBUG_FILE" + (( DEBUG == 1 )) && printf "%s: %s: ERR=%s, VHOST=%s, DATA=%s\\n" "$(date "+%Y%m%d %H%M%S.%N")" "exit read" "$ERR" "$LOG_VHOST" "${LOG_DATA:0:50}" >>"$DEBUG_FILE" # Determine how the read above was exited. if (( ERR > 128 )); then