110-startlogs.sh: better continuation of existing log file (even if empty).
This commit is contained in:
@ -6,6 +6,8 @@
|
||||
# Author: Kovács Zoltán <kovacsz@marcusconsulting.hu>
|
||||
# License: GNU/GPL v3+ (https://www.gnu.org/licenses/gpl-3.0.en.html)
|
||||
#
|
||||
# 2025-06-01 v0.4
|
||||
# fix: better continuation of existing log file (even if empty).
|
||||
# 2025-03-29 v0.3
|
||||
# mod: no longer repeats existing log lines.
|
||||
# 2025-02-26 v0.2
|
||||
@ -103,10 +105,11 @@ else
|
||||
[[ -n "$logline" ]] \
|
||||
&& timestamp="$(echo "$logline" | "$CUT" -d' ' -f1 2>/dev/null)" \
|
||||
|| timestamp="invalid"
|
||||
# Checks the validity.
|
||||
# If the log does not contain a valid last timestamp, we write log lines
|
||||
# created since the last time the container was started.
|
||||
[[ $("$DATE" -d "$timestamp" >/dev/null 2>&1; echo $?) -eq 0 ]] \
|
||||
&& since="$timestamp" \
|
||||
|| since="1970-01-01T00:00Z"
|
||||
|| since="$("$DOCKER" inspect -f '{{ .State.StartedAt }}' $container)"
|
||||
# Only logs the new lines (actually repeats the last one - TODO!).
|
||||
"$DOCKER" logs -t --since "$since" -f $container >> "$BASE_DIR/$LOGDIR/$service.log" 2>&1 &
|
||||
fi
|
||||
|
Reference in New Issue
Block a user