Skip to content

Commit ff0e917

Browse files
authored
Merge pull request #91 from deploymenttheory/dev
Fix default encoding in BuildLogger function
2 parents faa5e3e + 6863802 commit ff0e917

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

logger/zaplogger_config.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ import (
1212
// It configures the logger with JSON formatting and a custom encoder to ensure the 'pid', 'application', and 'timestamp' fields
1313
// appear at the end of each log message. The function panics if the logger cannot be initialized.
1414
func BuildLogger(logLevel LogLevel, encoding string, logConsoleSeparator string) Logger {
15+
// Set default encoding to console if not provided
16+
if encoding == "" {
17+
encoding = "console"
18+
}
1519

1620
// Set up custom encoder configuration
1721
encoderCfg := zap.NewProductionEncoderConfig()
@@ -39,11 +43,6 @@ func BuildLogger(logLevel LogLevel, encoding string, logConsoleSeparator string)
3943
// Name and function encoding (optional, depends on logging requirements)
4044
encoderCfg.EncodeName = zapcore.FullNameEncoder // Encodes the logger's name as-is, without any modifications.
4145

42-
// Console-specific settings (if using console encoding)
43-
if encoding == "console" {
44-
encoderCfg.ConsoleSeparator = logConsoleSeparator
45-
}
46-
4746
// Convert the custom LogLevel to zap's logging level
4847
zapLogLevel := convertToZapLevel(logLevel)
4948

0 commit comments

Comments
 (0)