Sync calls Sync on the underlying writer if possible.
(sinkName string)
| 49 | // Sync calls Sync on the underlying writer |
| 50 | // if possible. |
| 51 | func (w *Writer) Sync(sinkName string) { |
| 52 | w.mu.Lock() |
| 53 | defer w.mu.Unlock() |
| 54 | |
| 55 | s, ok := w.w.(syncer) |
| 56 | if !ok { |
| 57 | return |
| 58 | } |
| 59 | err := s.Sync() |
| 60 | if err != nil { |
| 61 | if _, ok := w.w.(*os.File); ok { |
| 62 | // Opened files do not necessarily support syncing. |
| 63 | // E.g. stdout and stderr both do not so we need |
| 64 | // to ignore these errors. |
| 65 | // See https://github.com/uber-go/zap/issues/370 |
| 66 | // See https://github.com/cdr/slog/pull/43 |
| 67 | if errorsIsAny(err, syscall.EINVAL, syscall.ENOTTY, syscall.EBADF) { |
| 68 | return |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | w.errorf("failed to sync %v: %+v", sinkName, err) |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | func errorsIsAny(err error, errs ...error) bool { |
| 77 | for _, e := range errs { |
nothing calls this directly
no test coverage detected