Skip to content

Conversation

@reitzig
Copy link

@reitzig reitzig commented Sep 4, 2025

Fixes #944

Changes

  • add new options, one per log level
  • use them

Demonstration

Test Script
#!/usr/bin/env bash

mkdir -p out
go build -o out -v ./...

log_all_levels() {
  echo "---"
  out/gum log --level=none  "Nothing"
  out/gum log --level=debug "A Detail"
  out/gum log --level=info  "A Note"
  out/gum log --level=warn  "A Warning"
  out/gum log --level=error "An Error"
  out/gum log --level=fatal "A Fuckup"
  echo "---"
}

echo "Defaults:"
log_all_levels || true
echo ""

echo "Legacy:"
export GUM_LOG_LEVEL_FOREGROUND="#ea76cb"
env | grep GUM_LOG_LEVEL_
log_all_levels || true
echo ""

echo "Some customization, fallback to legacy:"
echo "Style per level:"
export GUM_LOG_LEVEL_DEBUG_FOREGROUND="#6c6f85"
export GUM_LOG_LEVEL_INFO_FOREGROUND="#6c6f85"
env | grep GUM_LOG_LEVEL_
log_all_levels || true
echo ""

echo "Style per level:"
export GUM_LOG_LEVEL_DEBUG_FOREGROUND="#6c6f85"
export GUM_LOG_LEVEL_INFO_FOREGROUND="#04a5e5"
export GUM_LOG_LEVEL_WARN_FOREGROUND="#df8e1d"
export GUM_LOG_LEVEL_ERROR_FOREGROUND="#dd7878"
export GUM_LOG_LEVEL_FATAL_FOREGROUND="#d20f39"
env | grep GUM_LOG_LEVEL_
log_all_levels || true
image

@reitzig reitzig requested a review from a team as a code owner September 4, 2025 17:03
@reitzig reitzig requested review from kujtimiihoxha and tauraamui and removed request for a team September 4, 2025 17:03

// NB: Empirically determined that _this_ is what we get if we pass no CLI/Env args
var defaultLevelStyle = style.Styles{Align: "left", Bold: true, Border: "none", Margin: "0 0", Padding: "0 0"}
if reflect.DeepEqual(levelStyle, defaultLevelStyle) {
Copy link
Author

@reitzig reitzig Sep 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there's a neater way to check "has the user set any level.$level. option?", I'm all ears :)

Or a style merge, for that matter. 💁‍♂️

@reitzig
Copy link
Author

reitzig commented Sep 17, 2025

Not sure why GitHub proposed @tauraamui and @kujtimiihoxha as reviewers; @caarlos0 , how to best proceed here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

log -- configure colors per log level

1 participant