Skip to content

[bug] Debug logging silently discarded on file creation error #1815

@docker-agent

Description

@docker-agent

🟡 medium - bug

File: cmd/root/root.go (line 191)

Code

logFile, err := logging.NewRotatingFile(path)
if err != nil {
	return err
}
f.logFile = logFile

slog.SetDefault(slog.New(slog.NewTextHandler(logFile, &slog.HandlerOptions{Level: slog.LevelDebug})))

Problem

In setupLogging, if logging.NewRotatingFile(path) returns an error, the error is returned, but slog.SetDefault is never updated to write to the file. This means that if debug mode is enabled and an error occurs during log file creation, all subsequent debug logs will be silently discarded because the default logger remains slog.DiscardHandler from line 186.

Suggested Fix

If logging.NewRotatingFile returns an error, slog.SetDefault should be configured to write to cmd.ErrOrStderr() with debug level, similar to how it's handled in PersistentPreRunE for the initial logging setup. This ensures that debug logs are still visible even if file logging cannot be established.


Found by nightly codebase scan

Metadata

Metadata

Assignees

No one assigned

    Labels

    automatedIssues created by cagentkind/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions