2
0

110-startlogs.sh: better continuation of existing log file (even if empty).

This commit is contained in:
2025-06-15 12:39:42 +02:00
parent 8307b29649
commit 0211db1e08
2 changed files with 5 additions and 2 deletions

BIN
.metadata

Binary file not shown.

View File

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