Skip to content

Commit

Permalink
logging: Explain ERR_LOG_FILE && stdout redirection
Browse files Browse the repository at this point in the history
Signed-off-by: Michał Iwanicki <[email protected]>
  • Loading branch information
m-iwanicki committed Dec 20, 2024
1 parent f6159f6 commit a90f235
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 4 additions & 0 deletions scripts/dts-boot
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export DTS_VERBOSE_LOG_FILE
export ERR_LOG_FILE
export SHELLOPTS

# $ERR_LOG_FILE is fd that can only be written to: '>()'. To copy logs
# we need underlying file that can be copied
ERR_LOG_FILE_REALPATH="/var/local/dts-err_$(basename "$(tty)").log"
DTS_LOG_FILE="/tmp/dts_$(basename "$(tty)").log"
DTS_VERBOSE_LOG_FILE="/tmp/dts-verbose_$(basename "$(tty)").log"
Expand All @@ -28,6 +30,8 @@ source "$BASH_ENV"
start_trace_logging
start_logging
if [ -z "$ERR_LOG_FILE" ]; then
# pass everything written to $ERR_LOG_FILE to logger function and save it's
# output to $ERR_LOG_FILE_REALPATH file
exec {ERR_LOG_FILE}> >(logger >> "$ERR_LOG_FILE_REALPATH")
ERR_LOG_FILE="/proc/$$/fd/$ERR_LOG_FILE"
fi
Expand Down
4 changes: 3 additions & 1 deletion scripts/logging
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ logger() {
start_logging() {
local file="$DTS_LOG_FILE"
if [ -z "$LOGGING" ]; then
LOGGING="Y"
LOGGING="true"
if [ -z "$DESC" ]; then
# Create file descriptor that echoes back anything written to it
# and also logs that line to file with added timestamp prefix
exec {DESC}> >(tee >(stdbuf -i0 -oL -eL ts "[%T]: " >> "$file"))
fi
exec 1>&$DESC
Expand Down

0 comments on commit a90f235

Please sign in to comment.