From bc9652f156fcfeefdc9e3a29985ce410b672302b Mon Sep 17 00:00:00 2001 From: Darren 'Tadgy' Austin Date: Sun, 14 Jun 2020 17:23:35 +0100 Subject: [PATCH] Version 0.3.0 - support per second templates if required. Previously lumberjack was limited to per minute log files as the main loop would only be executed every minute if there were no log lines to be written. The timeout is now calculated as a fraction of the second, causing the read to timeout every second if there are no log lines to write. This allows the template to roll over every second if necessary, allowing per second logfiles. --- lumberjack | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/lumberjack b/lumberjack index 5d56cc5..6e968d5 100755 --- a/lumberjack +++ b/lumberjack @@ -8,7 +8,7 @@ # Script details. NAME="${0##*/}" -VERSION="0.2.2" +VERSION="0.3.0" # Functions. @@ -556,17 +556,11 @@ while :; do # Start compression jobs if there's any in the queue. start_compression_jobs - # The time until the top of the next minute - this is used for the 'read' timeout so that - # closing log files and compression can still occur even if no log lines are written. - # Note: This does mean we can't have per second log files, but I can't see that being a requirement. - # shellcheck disable=SC2183 - TTNM="$(( 60 - 10#$(printf "%(%S)T") ))" - - # Read the log line. - # Note: The $(...) expansion should *not* be quoted in this instance, and the space between - # $( and (( is necessary to quiet shellcheck. + # 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 the space between $( and (( is necessary to quiet shellcheck. # shellcheck disable=SC2046 - read -r -t "$TTNM" -u "$INPUTFD" $( (( FLAGS[raw] == 0 )) && printf "%s" "LOG_VHOST") LOG_DATA + read -r -t "0.$(( 999999999 - 10#$(date +%N) ))" -u "$INPUTFD" $( (( FLAGS[raw] == 0 )) && printf "%s" "LOG_VHOST") LOG_DATA ERR="$?" # Determine how the read above was exited.