Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Q: Logger migration #685

Closed
loeffel-io opened this issue Dec 22, 2023 · 2 comments
Closed

Q: Logger migration #685

loeffel-io opened this issue Dec 22, 2023 · 2 comments

Comments

@loeffel-io
Copy link

Hello!

i am curious how i would migrate our zap gcloud implementation from v2.0.0-rc3 to v2.0.1 - i am thankful for every help!

func NewZap(development bool) (*zap.Logger, error) {
	var err error
	var logger *zap.Logger

	var loggerCfg = &zap.Config{
		Level:       zap.NewAtomicLevelAt(zapcore.InfoLevel),
		Development: development,
		Encoding:    "json",
		EncoderConfig: zapcore.EncoderConfig{
			TimeKey:       "time",
			LevelKey:      "severity",
			NameKey:       "logger",
			CallerKey:     "caller",
			MessageKey:    "message",
			StacktraceKey: "stacktrace",
			LineEnding:    zapcore.DefaultLineEnding,
			EncodeLevel: func(l zapcore.Level, enc zapcore.PrimitiveArrayEncoder) {
				switch l {
				case zapcore.DebugLevel:
					enc.AppendString("DEBUG")
				case zapcore.InfoLevel:
					enc.AppendString("INFO")
				case zapcore.WarnLevel:
					enc.AppendString("WARNING")
				case zapcore.ErrorLevel:
					enc.AppendString("ERROR")
				case zapcore.DPanicLevel:
					enc.AppendString("CRITICAL")
				case zapcore.PanicLevel:
					enc.AppendString("ALERT")
				case zapcore.FatalLevel:
					enc.AppendString("EMERGENCY")
				}
			},
			EncodeTime:     zapcore.RFC3339TimeEncoder,
			EncodeDuration: zapcore.MillisDurationEncoder,
			EncodeCaller:   zapcore.ShortCallerEncoder,
		},
		OutputPaths:      []string{"stdout"},
		ErrorOutputPaths: []string{"stderr"},
	}

	if logger, err = loggerCfg.Build(zap.AddStacktrace(zap.DPanicLevel)); err != nil {
		return nil, err
	}

	return logger, nil
}
logging.StreamServerInterceptor(grpczap.InterceptorLogger(logger)),
@johanbrandhorst
Copy link
Collaborator

@loeffel-io
Copy link
Author

Yeah that works perfectly - was just curious if the lvls matches
Thanks @johanbrandhorst

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants