Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
d80tb7 committed Jan 12, 2025
1 parent a834009 commit e8cb59a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 30 deletions.
4 changes: 2 additions & 2 deletions internal/common/logging/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func createFileLogger(logConfig Config) (*FilteredLevelWriter, error) {
Compress: logConfig.File.Rotation.Compress,
}

if strings.ToLower(logConfig.File.Format) == "text" || strings.ToLower(logConfig.File.Format) == "colorful" {
if strings.ToLower(logConfig.File.Format) == "text" || strings.ToLower(logConfig.File.Format) == "colourful" {
return createConsoleWriter(lumberjackLogger, level, logConfig.File.Format), nil
} else {
return createJsonWriter(lumberjackLogger, level), nil
Expand All @@ -97,7 +97,7 @@ func createConsoleLogger(logConfig Config) (*FilteredLevelWriter, error) {
if err != nil {
return nil, err
}
if strings.ToLower(logConfig.Console.Format) == "text" || strings.ToLower(logConfig.Console.Format) == "colorful" {
if strings.ToLower(logConfig.Console.Format) == "text" || strings.ToLower(logConfig.Console.Format) == "colourful" {
return createConsoleWriter(os.Stdout, level, logConfig.Console.Format), nil
} else {
return createJsonWriter(os.Stdout, level), nil
Expand Down
40 changes: 12 additions & 28 deletions internal/common/logging/config.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package logging

import (

Check failure on line 3 in internal/common/logging/config.go

View workflow job for this annotation

GitHub Actions / lint / Lint Go

File is not `gofumpt`-ed (gofumpt)
"strings"

"github.com/pkg/errors"
"go.uber.org/zap/zapcore"
"github.com/rs/zerolog"
"golang.org/x/exp/maps"
"strings"

Check failure on line 7 in internal/common/logging/config.go

View workflow job for this annotation

GitHub Actions / lint / Lint Go

File is not `gofumpt`-ed (gofumpt)
)

var validLogFormats = map[string]bool{
"text": true,
"json": true,
"colorful": true,
"text": true,
"json": true,
"colourful": true,
}

// Config defines Armada logging configuration.
Expand Down Expand Up @@ -50,7 +49,7 @@ type Config struct {
}

func validate(c Config) error {
_, err := parseLogLevel(c.Console.Level)
_, err := zerolog.ParseLevel(c.Console.Level)
if err != nil {
return err
}
Expand All @@ -61,7 +60,7 @@ func validate(c Config) error {
}

if c.File.Enabled {
_, err := parseLogLevel(c.File.Level)
_, err := zerolog.ParseLevel(c.File.Level)
if err != nil {
return err
}
Expand Down Expand Up @@ -91,27 +90,12 @@ func validate(c Config) error {
func validateLogFormat(f string) error {
_, ok := validLogFormats[f]
if !ok {
err := errors.Errorf("unknown log format: %s. Valid formats are %s", f, maps.Keys(validLogFormats))
err := errors.Errorf(
"unknown log format: %s. Valid formats are %s",
f,
strings.Join(maps.Keys(validLogFormats), ","),
)
return err
}
return nil
}

func parseLogLevel(level string) (zapcore.Level, error) {
switch strings.ToLower(level) {
case "debug":
return zapcore.DebugLevel, nil
case "info":
return zapcore.InfoLevel, nil
case "warn", "warning":
return zapcore.WarnLevel, nil
case "error":
return zapcore.ErrorLevel, nil
case "panic":
return zapcore.PanicLevel, nil
case "fatal":
return zapcore.FatalLevel, nil
default:
return zapcore.InfoLevel, errors.Errorf("unknown level: %s", level)
}
}

0 comments on commit e8cb59a

Please sign in to comment.