File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -55,11 +55,29 @@ var rootCmd = &cobra.Command{
55
55
var noColor bool
56
56
if ! isatty .IsTerminal (os .Stdout .Fd ()) {
57
57
noColor = true
58
+ color .Disable ()
58
59
}
59
60
slog .SetDefault (slog .New (tint .NewHandler (os .Stdout , & tint.Options {
60
61
Level : level ,
61
62
NoColor : noColor ,
62
63
TimeFormat : time .StampMilli ,
64
+ ReplaceAttr : func (groups []string , attr slog.Attr ) slog.Attr {
65
+ if attr .Key != "level" {
66
+ return attr
67
+ }
68
+
69
+ switch attr .Value .String () {
70
+ case slog .LevelDebug .String ():
71
+ attr .Value = slog .StringValue (color .Gray .Render ("[DEBUG]" ))
72
+ case slog .LevelInfo .String ():
73
+ attr .Value = slog .StringValue (color .Green .Render ("[INFO ]" ))
74
+ case slog .LevelWarn .String ():
75
+ attr .Value = slog .StringValue (color .Yellow .Render ("[WARN ]" ))
76
+ case slog .LevelError .String ():
77
+ attr .Value = slog .StringValue (color .Red .Render ("[ERROR]" ))
78
+ }
79
+ return attr
80
+ },
63
81
})))
64
82
65
83
cfg , err := config .LoadConfig (rootOpts .ConfigLocation )
You can’t perform that action at this time.
0 commit comments