Skip to content
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

Implemented SyncWriter interface #183

Open
wants to merge 1 commit into
base: v2.0
Choose a base branch
from

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