-
-
Notifications
You must be signed in to change notification settings - Fork 125
Style Atmos Logger with Theme #1135
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
Changes from all commits
e54747d
9309d1f
a25ed56
1c8a36f
3a026e3
0dd18a2
9dbefce
12c4218
b3e0f76
5923af5
c7fcd72
bc8e37e
4ed7257
4a98c4a
c62904f
684d91e
52ad0f6
c9fa7cd
19b75f1
b27dc59
1b9fbe7
538f735
555074e
b58ee5b
06f86a7
ede568a
e371854
1e19569
26ded14
13bb48a
4c1e4c2
cb40e1f
58fc21e
667b259
7b25bed
ece8630
3a53501
a8d1d6e
fde8f5e
4820f56
d83e510
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -9,7 +9,7 @@ | |||||
"regexp" | ||||||
"strings" | ||||||
|
||||||
"github.com/charmbracelet/log" | ||||||
log "github.com/charmbracelet/log" | ||||||
"github.com/elewis787/boa" | ||||||
"github.com/spf13/cobra" | ||||||
|
||||||
|
@@ -80,21 +80,7 @@ | |||||
} | ||||||
|
||||||
func setupLogger(atmosConfig *schema.AtmosConfiguration) { | ||||||
switch atmosConfig.Logs.Level { | ||||||
case "Trace": | ||||||
log.SetLevel(log.DebugLevel) | ||||||
case "Debug": | ||||||
log.SetLevel(log.DebugLevel) | ||||||
case "Info": | ||||||
log.SetLevel(log.InfoLevel) | ||||||
case "Warning": | ||||||
log.SetLevel(log.WarnLevel) | ||||||
case "Off": | ||||||
log.SetLevel(math.MaxInt32) | ||||||
default: | ||||||
log.SetLevel(log.InfoLevel) | ||||||
} | ||||||
|
||||||
// Determine output writer based on configuration. | ||||||
var output io.Writer | ||||||
|
||||||
switch atmosConfig.Logs.File { | ||||||
|
@@ -113,12 +99,44 @@ | |||||
output = logFile | ||||||
} | ||||||
|
||||||
log.SetOutput(output) | ||||||
atmosLogger := logger.NewAtmosLogger(output) | ||||||
|
||||||
// Set the global log instance to our styled logger. | ||||||
log.SetDefault(atmosLogger) | ||||||
|
||||||
// Set the appropriate log level based on configuration. | ||||||
switch atmosConfig.Logs.Level { | ||||||
case "Trace": | ||||||
atmosLogger.SetLevel(logger.AtmosTraceLevel) | ||||||
case "Debug": | ||||||
atmosLogger.SetLevel(log.DebugLevel) | ||||||
case "Info": | ||||||
atmosLogger.SetLevel(log.InfoLevel) | ||||||
case "Warning": | ||||||
atmosLogger.SetLevel(log.WarnLevel) | ||||||
case "Error": | ||||||
atmosLogger.SetLevel(log.ErrorLevel) | ||||||
case "Off": | ||||||
atmosLogger.SetLevel(math.MaxInt32) | ||||||
default: | ||||||
atmosLogger.SetLevel(log.InfoLevel) | ||||||
} | ||||||
|
||||||
if _, err := logger.ParseLogLevel(atmosConfig.Logs.Level); err != nil { | ||||||
//nolint:all // The reason to escape this is because it is expected to fail fast. The reason for ignoring all is because we also get a lint error to execute defer logFile.Close() before this but that is not required | ||||||
log.Fatal(err) | ||||||
} | ||||||
log.Debug("Set", "logs-level", log.GetLevel(), "logs-file", atmosConfig.Logs.File) | ||||||
// Use the log level from config directly for consistent output | ||||||
logLevelStr := strings.ToLower(atmosConfig.Logs.Level) | ||||||
if logLevelStr == "" { | ||||||
logLevelStr = "info" // Default value if not specified | ||||||
} | ||||||
|
||||||
if strings.ToLower(atmosConfig.Logs.Level) == "trace" { | ||||||
log.Log(logger.AtmosTraceLevel, "Set", "logs-level", logLevelStr, "logs-file", atmosConfig.Logs.File) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} else { | ||||||
log.Debug("Set", "logs-level", logLevelStr, "logs-file", atmosConfig.Logs.File) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here we use We should be consistent. https://github.com/cloudposse/atmos/pull/1135/files#r2004173296 I'm okay changing it to |
||||||
} | ||||||
} | ||||||
|
||||||
// Execute adds all child commands to the root command and sets flags appropriately. | ||||||
|
Uh oh!
There was an error while loading. Please reload this page.