Skip to content

Commit

Permalink
bool type declaration
Browse files Browse the repository at this point in the history
Signed-off-by: Austin Abro <[email protected]>
  • Loading branch information
AustinAbro321 committed Dec 10, 2024
1 parent 68562f0 commit a49ea28
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func setupLogger(level, format string, color bool) (*slog.Logger, error) {
Level: sLevel,
Format: logger.Format(format),
Destination: logger.DestinationDefault,
Color: color,
Color: logger.Color(color),
}
l, err := logger.New(cfg)
if err != nil {
Expand Down
11 changes: 7 additions & 4 deletions src/pkg/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,19 @@ type Config struct {
Level
Format
Destination
Color bool
Color
}

// Color is a type that represents whether or not to use color in the logger.
type Color bool

// LogValue of config
func (c Config) LogValue() slog.Value {
return slog.GroupValue(
slog.String("level", c.Level.String()),
slog.Any("format", c.Format),
slog.Any("destination", destinationString(c.Destination)),
slog.Bool("color", c.Color),
slog.Bool("color", bool(c.Color)),
)
}

Expand Down Expand Up @@ -175,7 +178,7 @@ func New(cfg Config) (*slog.Logger, error) {
case FormatConsole:
handler = console.NewHandler(cfg.Destination, &console.HandlerOptions{
Level: slog.Level(cfg.Level),
NoColor: !cfg.Color,
NoColor: !bool(cfg.Color),
})
case FormatJSON:
handler = slog.NewJSONHandler(cfg.Destination, &opts)
Expand All @@ -188,7 +191,7 @@ func New(cfg Config) (*slog.Logger, error) {
handler = devslog.NewHandler(DestinationDefault, &devslog.Options{
HandlerOptions: &opts,
NewLineAfterLog: true,
NoColor: !cfg.Color,
NoColor: !bool(cfg.Color),
})
// Use discard handler if no format provided
case "", FormatNone:
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/logger/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func Test_New(t *testing.T) {
},
},
{
name: "color can be true",
name: "color true is ok",
cfg: Config{
Color: true,
},
Expand Down

0 comments on commit a49ea28

Please sign in to comment.