2020-02-09 19:46:33 +03:00
|
|
|
package zap
|
|
|
|
|
|
|
|
import (
|
|
|
|
"go.uber.org/zap"
|
|
|
|
"go.uber.org/zap/zapcore"
|
2020-02-21 12:31:16 +03:00
|
|
|
|
2021-01-10 15:41:04 +03:00
|
|
|
"github.com/unistack-org/micro/v3/logger"
|
2020-02-09 19:46:33 +03:00
|
|
|
)
|
|
|
|
|
2020-03-04 01:04:22 +03:00
|
|
|
type callerSkipKey struct{}
|
|
|
|
|
|
|
|
func WithCallerSkip(i int) logger.Option {
|
|
|
|
return logger.SetOption(callerSkipKey{}, i)
|
|
|
|
}
|
|
|
|
|
2020-02-09 19:46:33 +03:00
|
|
|
type configKey struct{}
|
|
|
|
|
|
|
|
// WithConfig pass zap.Config to logger
|
|
|
|
func WithConfig(c zap.Config) logger.Option {
|
2020-02-21 12:31:16 +03:00
|
|
|
return logger.SetOption(configKey{}, c)
|
2020-02-09 19:46:33 +03:00
|
|
|
}
|
|
|
|
|
2021-01-10 15:41:04 +03:00
|
|
|
type loggerKey struct{}
|
|
|
|
|
|
|
|
// WithLogger pass *zap.Logger to logger
|
|
|
|
func WithLogger(l *zap.Logger) logger.Option {
|
|
|
|
return logger.SetOption(loggerKey{}, l)
|
|
|
|
}
|
|
|
|
|
2020-02-09 19:46:33 +03:00
|
|
|
type encoderConfigKey struct{}
|
|
|
|
|
|
|
|
// WithEncoderConfig pass zapcore.EncoderConfig to logger
|
|
|
|
func WithEncoderConfig(c zapcore.EncoderConfig) logger.Option {
|
2020-02-21 12:31:16 +03:00
|
|
|
return logger.SetOption(encoderConfigKey{}, c)
|
2020-02-09 19:46:33 +03:00
|
|
|
}
|
|
|
|
|
2020-02-21 12:31:16 +03:00
|
|
|
type namespaceKey struct{}
|
2020-02-09 19:46:33 +03:00
|
|
|
|
2020-02-21 12:31:16 +03:00
|
|
|
func WithNamespace(namespace string) logger.Option {
|
|
|
|
return logger.SetOption(namespaceKey{}, namespace)
|
2020-02-09 19:46:33 +03:00
|
|
|
}
|