Skip to content

Log Records getting skipped after rotation #1448

Open
@Akhilesh53

Description

Describe the bug
After rotation (creation of a new file) the very first log line is skipped and is not showing in log file.

To Reproduce
`func initiliaselogger() {
level := getLevel(env.ENV.LOG_LEVEL)

devConfig := zap.NewDevelopmentEncoderConfig()
prodConfig := zap.NewProductionEncoderConfig()

devConfig.EncodeTime = zapcore.RFC3339NanoTimeEncoder
prodConfig.EncodeTime = zapcore.RFC3339NanoTimeEncoder
hostname, err := os.Hostname()
if err != nil {
	hostname = ""
}
if hostname != "" {
	hostname = "_" + hostname
}
filewriter := zapcore.AddSync(&lumberjack.Logger{
	Filename:   "logs/regulatory/" + strings.ToLower(strings.ReplaceAll(env.ENV.PROCESS_NAME+hostname, " ", "_")) + ".log",
	MaxSize:    40,
	MaxAge:     30,
	MaxBackups: 100,
	Compress:   false, // disabled by default
})
core := zapcore.NewCore(zapcore.NewJSONEncoder(prodConfig), filewriter, level)

if env.ENV.ENVIRONMENT == "dev" {
	core = zapcore.NewTee(
		core,
		zapcore.NewCore(zapcore.NewConsoleEncoder(devConfig), zapcore.Lock(os.Stdout), level),
	)
}

if env.ENV.KAFKA_LOG == "Y" {
	kafkaSync := zapcore.AddSync(getKafkaWriter())
	core = zapcore.NewTee(
		core,
		zapcore.NewCore(zapcore.NewJSONEncoder(prodConfig), kafkaSync, level),
	)
}

Log = zap.New(core,
	zap.AddCaller(),
	zap.AddCallerSkip(1),
	zap.AddStacktrace(zap.ErrorLevel),
)

}`

Expected behavior
After the creation of a new file (after rotation), the very line of the log is skipped.

Pls let me know if I have to change anything in the configuration while initializing the logger.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions