MCPcopy Create free account
hub / github.com/coder/slog / Sync

Method Sync

internal/syncwriter/syncwriter.go:51–74  ·  view source on GitHub ↗

Sync calls Sync on the underlying writer if possible.

(sinkName string)

Source from the content-addressed store, hash-verified

49// Sync calls Sync on the underlying writer
50// if possible.
51func (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
76func errorsIsAny(err error, errs ...error) bool {
77 for _, e := range errs {

Callers

nothing calls this directly

Calls 1

errorsIsAnyFunction · 0.85

Tested by

no test coverage detected