chore: make codes the repository root

This commit is contained in:
Eric 1549169735@qq.com
2026-08-06 21:52:03 +08:00
parent de5345607a
commit 23c9f52869
89 changed files with 21 additions and 513 deletions

28
internal/logger/logger.go Normal file
View 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
}