-
Notifications
You must be signed in to change notification settings - Fork 0
/
writer.go
39 lines (31 loc) · 910 Bytes
/
writer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package zapappender
import (
"syscall"
"go.uber.org/zap/zapcore"
)
var _ Appender = &Writer{}
// Writer outputs the message to a zapcore.WriteSyncer
type Writer struct {
out zapcore.WriteSyncer
}
func NewWriter(out zapcore.WriteSyncer) *Writer {
return &Writer{out: out}
}
func (a *Writer) Write(p []byte, _ zapcore.Entry) (n int, err error) {
return a.out.Write(p)
}
func (a *Writer) Sync() error {
// ignore non-actionable errors
// as per https://github.com/open-telemetry/opentelemetry-collector/issues/4153
// and https://github.com/open-telemetry/opentelemetry-collector/blob/2116719e97eb232a692364b51454620712823a89/exporter/loggingexporter/known_sync_error.go#L35
// TODO: windows implementation
err := a.out.Sync()
switch err {
case syscall.EINVAL, syscall.ENOTSUP, syscall.ENOTTY, syscall.EBADF:
return nil
}
return err
}
func (a *Writer) Synchronized() bool {
return true
}