-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
invalid compressed data--format violated #1392
Comments
Can you please clarify your setup a little bit? Zap just writes to a file without compression by default. If you have specific configuration that syncs as a gzip formatted file, maybe that custom zapcore implementation might have issues; But zap by default does not write its output as a gzip'd file. |
here func initLogger(filePath string, atomicLevel *zap.AtomicLevel, fields ...zap.Field) (*FMLogger, error) {
// 创建日志配置
var encoderConfig = zap.NewProductionEncoderConfig()
encoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
// 创建Console输出Core
consoleEncoder := zapcore.NewJSONEncoder(encoderConfig)
consoleCore := zapcore.NewCore(consoleEncoder, zapcore.Lock(os.Stdout), atomicLevel)
// 创建日志输出Core
fmt.Printf("Init logger setting: MaxSize: %d, MaxAge: %d, MaxBackups: %d, logPath: %s\n",
config.GlobalConfig.LogRotateSize, config.GlobalConfig.LogMaxAge, config.GlobalConfig.LogBackupCount, filePath)
fileWriter := zapcore.AddSync(&lumberjack.Logger{
Filename: filePath,
MaxSize: config.GlobalConfig.LogRotateSize, // megabytes
MaxAge: config.GlobalConfig.LogMaxAge, // backup log files 7 Days
MaxBackups: config.GlobalConfig.LogBackupCount, // backup log files 100
Compress: true,
})
fileCore := zapcore.NewCore(
zapcore.NewJSONEncoder(encoderConfig),
fileWriter,
atomicLevel,
)
cores := zapcore.NewTee(fileCore, consoleCore)
log := zap.New(cores)
log = log.WithOptions(
zap.ErrorOutput(os.Stdout), // error message output to stdout
zap.AddCaller(), // add function caller info to log
zap.AddCallerSkip(1), // make stack having right depth to get function call
zap.Fields(fields...), // add common log info, like local_ip
)
logger := FMLogger{
logger: log.Sugar(),
ctx: context.Background(),
}
return &logger, nil
} Maybe because of ' lumberjack'? I'm not sure that. fileWriter := zapcore.AddSync(&lumberjack.Logger{
Filename: filePath,
MaxSize: config.GlobalConfig.LogRotateSize, // megabytes
MaxAge: config.GlobalConfig.LogMaxAge, // backup log files 7 Days
MaxBackups: config.GlobalConfig.LogBackupCount, // backup log files 100
Compress: true,
}) |
Hi @wuyinq, it seems like the compressed files you're referring to are coming from a lumberjack Logger. Zap doesn't have any control over what lumberjack is writing to disk. I'd suggest asking the maintainers of lumberjack. |
yes, I'm waiting for their reply. |
Describe the bug
when I use 'zap' to manager my service log, i find sometimes the **.log.gz can't be unzip using 'gunzip' command.
I get this when i run "gunzip ***.log.gz":
The text was updated successfully, but these errors were encountered: