Skip to content

Commit e681b86

Browse files
committed
lib/log: Use printf -v to create formatted message
Seems a little easier to understand the message format this way, and using `%b` in the `printf -v` statement seems less subtle than using it in the `printf` that actually generates the output.
1 parent 8e4b6fd commit e681b86

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lib/log

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,10 @@ readonly __GO_LOG_COMMAND_EXIT_PATTERN='^@go.log_command (exit|fatal):([0-9]+)$'
251251

252252
local __go_log_timestamp
253253
if @go.log_timestamp; then
254-
log_msg="$__go_log_timestamp "
254+
__go_log_timestamp+=' '
255255
fi
256-
log_msg+="${__GO_LOG_LEVELS_FORMATTED[$__go_log_level_index]} "
257-
log_msg+="${args[*]}\\e[0m"
256+
printf -v log_msg -- '%s%b %b' "$__go_log_timestamp" \
257+
"${__GO_LOG_LEVELS_FORMATTED[$__go_log_level_index]}" "${args[*]}\\e[0m"
258258

259259
local __go_log_level_file_descriptors=('1')
260260
if [[ "$__GO_LOG_COMMAND_DEPTH" == '0' || "$log_level" != 'RUN' ]]; then
@@ -271,7 +271,7 @@ readonly __GO_LOG_COMMAND_EXIT_PATTERN='^@go.log_command (exit|fatal):([0-9]+)$'
271271
fi
272272
printf '%s\n' "$stripped_log_msg" >&"$level_fd"
273273
else
274-
printf '%b\n' "$log_msg" >&"$level_fd"
274+
printf '%s\n' "$log_msg" >&"$level_fd"
275275
fi
276276

277277
if [[ "$log_level" == 'FATAL' ]]; then

0 commit comments

Comments
 (0)