Skip to content

Conversation

@piyongcai
Copy link

Implemented SyncWriter interface.

In some scenarios, we need to use the SyncWriter interface, such as integrating lumberjack and go.uber.org/zap.

@piyongcai
Copy link
Author

@elithrar
Please check and merge!!

@elithrar
Copy link
Contributor

Please don't ping me. I don't have any relationship to this package.

@liuzengh
Copy link

@piyongcai you can use zapcore.AddSync to wrap lumberjack.Logger :

// lumberjack.Logger is already safe for concurrent use, so we don't need to
// lock it.
w := zapcore.AddSync(&lumberjack.Logger{
  Filename:   "/var/log/myapp/foo.log",
  MaxSize:    500, // megabytes
  MaxBackups: 3,
  MaxAge:     28, // days
})
core := zapcore.NewCore(
  zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig()),
  w,
  zap.InfoLevel,
)
logger := zap.New(core)

logger.Info("Hello, world!")

@remones
Copy link

remones commented Jul 28, 2024

@liuzengh but zapcore.AddSync returns a fake SyncWriter, right? It doesn't call file.Sync()

@rohan-rayaraddi
Copy link

@natefinch can this be merged?

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

Successfully merging this pull request may close these issues.

6 participants