Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion pkg/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ type Logger struct {

var (
// DEBUG environment variable value, read once at initialization.
debugEnv = os.Getenv("DEBUG")
// If DEBUG is not set but ACTIONS_RUNNER_DEBUG=true, all loggers are enabled.
debugEnv = initDebugEnv()

// DEBUG_COLORS environment variable to control color output.
debugColors = os.Getenv("DEBUG_COLORS") != "0"
Expand Down Expand Up @@ -51,6 +52,19 @@ var (
colorReset = "\033[0m"
)

// initDebugEnv resolves the effective debug pattern.
// If DEBUG is set, it takes precedence. Otherwise, if ACTIONS_RUNNER_DEBUG=true,
// all loggers are enabled (equivalent to DEBUG=*).
func initDebugEnv() string {
if d := os.Getenv("DEBUG"); d != "" {
return d
}
if os.Getenv("ACTIONS_RUNNER_DEBUG") == "true" {
return "*"
Comment on lines +58 to +63
}
return ""
}

// New creates a new Logger for the given namespace.
// The enabled state is computed at construction time based on the DEBUG environment variable.
// DEBUG syntax follows https://www.npmjs.com/package/debug patterns:
Expand Down
46 changes: 46 additions & 0 deletions pkg/logger/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,52 @@ func TestColorDisabling(t *testing.T) {
}
}

func TestInitDebugEnv(t *testing.T) {
tests := []struct {
name string
debugEnvVal string
actionsRunnerDebug string
want string
}{
{
name: "DEBUG takes precedence over ACTIONS_RUNNER_DEBUG",
debugEnvVal: "cli:*",
actionsRunnerDebug: "true",
want: "cli:*",
},
{
name: "ACTIONS_RUNNER_DEBUG=true enables all loggers",
debugEnvVal: "",
actionsRunnerDebug: "true",
want: "*",
},
{
name: "ACTIONS_RUNNER_DEBUG=false does not enable loggers",
debugEnvVal: "",
actionsRunnerDebug: "false",
want: "",
},
{
name: "neither set returns empty",
debugEnvVal: "",
actionsRunnerDebug: "",
want: "",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Setenv("DEBUG", tt.debugEnvVal)
t.Setenv("ACTIONS_RUNNER_DEBUG", tt.actionsRunnerDebug)

Comment on lines +337 to +372
got := initDebugEnv()
if got != tt.want {
t.Errorf("initDebugEnv() = %q, want %q", got, tt.want)
}
})
}
}

func TestMatchPattern(t *testing.T) {
tests := []struct {
name string
Expand Down
Loading