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.
This commit is contained in:
Darren 'Tadgy' Austin 2020-06-14 17:23:35 +01:00
commit bc9652f156

View file

@ -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.