Open prasanjitm opened 3 years ago
I am using zap with lumberjack. I have multiple log files for the application. But only one file is rotated where as other is not.
As per the below code, only the /opt/logs/request.json is rotated and the other is not. What may be the issue.
var reqLogger *zap.Logger type lumberjackSink struct { *lumberjack.Logger } func (lumberjackSink) Sync() error { return nil } func InitApiLogger(environment string) { logLevel := zapcore.InfoLevel reqLogger = initializeLogger("/opt/logs/request.json", logLevel, "requestLogger") applicationLogger = initializeLogger("/opt/logs/app.json", logLevel, "applicationLogger") } func initializeLogger(logFile string, logLevel zapcore.Level, logType string) *zap.Logger { zapConfig := zap.NewProductionConfig() zapConfig.DisableStacktrace = false zapConfig.DisableCaller = false zapConfig.EncoderConfig.EncodeTime = syslogTimeEncoder zapConfig.Level.SetLevel(logLevel) zap.RegisterSink(logType, func(u *url.URL) (zap.Sink, error) { return lumberjackSink{ Logger: &lumberjack.Logger{ Filename: logFile, MaxSize: 1, MaxBackups: 10, MaxAge: 10, Compress: false, }, }, nil }) zapConfig.OutputPaths = []string{fmt.Sprintf("%s:%s", logType, logFile)} zapConfig.ErrorOutputPaths = []string{fmt.Sprintf("%s:%s", logType, logFile)} var loggerBuildErr error logger, loggerBuildErr := zapConfig.Build() if loggerBuildErr != nil { panic(fmt.Errorf("error in building zap application logger: %s", loggerBuildErr)) } return logger } // Return the logger object func GetRequestLogger() *zap.Logger { return reqLogger } // Return the logger object func GetApplicationLogger() *zap.Logger { return applicationLogger } func syslogTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder) { enc.AppendString(t.Format(constants.LoggingDateFormat)) }
@natefinch any idea?
do you already found any solution ? same here, I want to write some log into different files
I am using zap with lumberjack. I have multiple log files for the application. But only one file is rotated where as other is not.
As per the below code, only the /opt/logs/request.json is rotated and the other is not. What may be the issue.