Logging and Observability
Log Level
Choose Detail
A logging helper can select how much detail to write while keeping the output format stable for readers and tools.
Program
Play the script to choose the log level and see the resulting log line.
log_level_line.sh
Replay: real traced execution (multi-file project)
#!/usr/bin/env bash
level="info"
case "$level" in
info) message="service ready" ;;
debug) message="cache warmed" ;;
esac
line="$level:$message"
echo "$line"
#!/usr/bin/env bash
level="debug"
case "$level" in
info) message="service ready" ;;
debug) message="cache warmed" ;;
esac
line="$level:$message"
echo "$line"
level ← info
3level="info"4case "$level" invalues this stepinfolevelcase "$level" in
3level="info"4case "$level" in5 info) message="service ready" ;;values this stepinfolevelmessage ← service ready
4case "$level" in5 info) message="service ready" ;;6 debug) message="cache warmed" ;;values this stepservice readymessageline ← info:service ready
7esac8line="$level:$message"9echo "$line"values this stepinfo:service readylineinfolevelservice readymessageecho "$line"
8line="$level:$message"9echo "$line"outputinfo:service readyvalues this stepinfo:service readyline
level ← debug
3level="debug"4case "$level" invalues this stepdebuglevelcase "$level" in
3level="debug"4case "$level" in5 info) message="service ready" ;;values this stepdebuglevelmessage ← cache warmed
5 info) message="service ready" ;;6 debug) message="cache warmed" ;;7esacvalues this stepcache warmedmessageline ← debug:cache warmed
7esac8line="$level:$message"9echo "$line"values this stepdebug:cache warmedlinedebuglevelcache warmedmessageecho "$line"
8line="$level:$message"9echo "$line"outputdebug:cache warmedvalues this stepdebug:cache warmedline
log level
The log level names how detailed the message is.
stable format
A stable log shape is easier to search and parse.
message
The message carries the human-readable event detail.