chore: make codes the repository root
This commit is contained in:
28
internal/logger/logger.go
Normal file
28
internal/logger/logger.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package logger
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapcore"
|
||||
)
|
||||
|
||||
func New(environment, service string) (*zap.Logger, error) {
|
||||
var cfg zap.Config
|
||||
if strings.EqualFold(environment, "prod") || strings.EqualFold(environment, "production") {
|
||||
cfg = zap.NewProductionConfig()
|
||||
cfg.EncoderConfig.TimeKey = "time"
|
||||
cfg.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
|
||||
} else {
|
||||
cfg = zap.NewDevelopmentConfig()
|
||||
cfg.EncoderConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder
|
||||
}
|
||||
cfg.OutputPaths = []string{"stdout"}
|
||||
cfg.ErrorOutputPaths = []string{"stderr"}
|
||||
|
||||
log, err := cfg.Build()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return log.With(zap.String("service", service), zap.String("env", environment)), nil
|
||||
}
|
||||
Reference in New Issue
Block a user