-
Notifications
You must be signed in to change notification settings - Fork 4
/
direct_writer.go
62 lines (49 loc) · 1.26 KB
/
direct_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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package logwriter
import (
"io"
"github.com/insolar/assured-ledger/ledger-core/log/logcommon"
)
func NewDirectWriter(output *Adapter) *FatalDirectWriter {
if output == nil {
panic("illegal value")
}
return &FatalDirectWriter{
output: output,
}
}
var _ logcommon.LogLevelWriter = &FatalDirectWriter{}
var _ io.WriteCloser = &FatalDirectWriter{}
type FatalDirectWriter struct {
output *Adapter
}
func (p *FatalDirectWriter) Close() error {
return p.output.Close()
}
func (p *FatalDirectWriter) Flush() error {
return p.output.Flush()
}
func (p *FatalDirectWriter) Write(b []byte) (n int, err error) {
return p.output.Write(b)
}
func (p *FatalDirectWriter) LowLatencyWrite(level logcommon.Level, b []byte) (int, error) {
return p.LogLevelWrite(level, b)
}
func (p *FatalDirectWriter) IsLowLatencySupported() bool {
return false
}
func (p *FatalDirectWriter) LogLevelWrite(level logcommon.Level, b []byte) (n int, err error) {
switch level {
case logcommon.FatalLevel:
if !p.output.SetFatal() {
break
}
n, _ = p.output.DirectLevelWrite(level, b)
_ = p.output.DirectFlushFatal()
return n, nil
case logcommon.PanicLevel:
n, err = p.output.LogLevelWrite(level, b)
_ = p.output.Flush()
return n, err
}
return p.output.LogLevelWrite(level, b)
}