Skip to content

support setting log level for backend #1958

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 27, 2025
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
15 changes: 14 additions & 1 deletion backend/bootstrap/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,21 @@ func Bootstrap(templates embed.FS, diggerController controllers.DiggerController
}

func initLogging() {
logLevel := os.Getenv("DIGGER_LOG_LEVEL")
var level slog.Leveler

if logLevel == "DEBUG" {
level = slog.LevelDebug
} else if logLevel == "WARN" {
level = slog.LevelWarn
} else if logLevel == "ERROR" {
level = slog.LevelError
} else {
level = slog.LevelInfo
}

handler := slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{
Level: slog.LevelInfo,
Level: level,
})
logger := slog.New(handler)
slog.SetDefault(logger)
Expand Down
2 changes: 2 additions & 0 deletions cli/cmd/digger/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ func initLogger() {
var level slog.Leveler
if logLevel == "DEBUG" {
level = slog.LevelDebug
} else if logLevel == "WARN" {
level = slog.LevelWarn
Comment on lines +27 to +28
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add ERROR level support for consistency with backend.

The WARN level support looks good, but there's an inconsistency: the backend supports ERROR level while the CLI doesn't. For consistent behavior across components, consider adding ERROR level support.

 	if logLevel == "DEBUG" {
 		level = slog.LevelDebug
 	} else if logLevel == "WARN" {
 		level = slog.LevelWarn
+	} else if logLevel == "ERROR" {
+		level = slog.LevelError
 	} else {
 		level = slog.LevelInfo
 	}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
} else if logLevel == "WARN" {
level = slog.LevelWarn
if logLevel == "DEBUG" {
level = slog.LevelDebug
} else if logLevel == "WARN" {
level = slog.LevelWarn
} else if logLevel == "ERROR" {
level = slog.LevelError
} else {
level = slog.LevelInfo
}
🤖 Prompt for AI Agents
In cli/cmd/digger/default.go around lines 27 to 28, the code handles the WARN
log level but lacks support for the ERROR log level, causing inconsistency with
the backend. Add a condition to check if logLevel equals "ERROR" and set level
to slog.LevelError accordingly to ensure consistent log level handling across
components.

} else {
level = slog.LevelInfo
}
Expand Down
Loading