Open caevv opened 3 years ago
Thanks for the report @caevv
This is a known issue, see previous threads related to this: #772 and #370.
The error itself is slightly different on OS X vs Linux.
OS X: inappropriate ioctl for device
Linux: sync /dev/stderr: invalid argument
The error only happens when stdout/stderr point to the console, but not if they are redirected to a file (since files support sync).
I think it's worth considering some workarounds for this issue it's a common scenario. A couple of possible ideas:
Sync
(for any file)Sync
, and if returns an error, then ignore future Sync
errors (if they are the same).Can we have errors.Is(err, zap.ErrConsoleSync)
in the mean time?
This error comes from the underlying platform, so to achieve the above, we'd need to have platform-specific detection, and wrapping of the errors in zap. So it would require a similar amount of work in zap first.
Hey, it's been almost a year. Is there any update on this issue?
Using this as a hotfix. correct me if I have done anything wrong.
lc.Append(fx.Hook{
++ OnStart: func(c context.Context) error {
++ if logger.Sync() != nil {
++ ignoreSync = true
++ }
++ return nil
++ },
OnStop: func(ctx context.Context) error {
++ if ignoreSync {
++ return nil
++ }
err := logger.Sync()
return eris.Wrap(err, "log: could not sync before exit")
},
})
any update?
any update?
any update?
I think you can use this approach for now: https://github.com/uber-go/zap/issues/991#issuecomment-962098428
Up, experienced the same behavior using v1.16.0
, Apple Silicon, Sonoma 14.5.
Both on mac and linux I get this error when doing
zapLogger.Sync()
:Code: