-
Notifications
You must be signed in to change notification settings - Fork 23
/
handler_stdout.go
62 lines (50 loc) · 1.1 KB
/
handler_stdout.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 logging
import (
"os"
)
type StdoutStream struct {
stdout *os.File
}
func NewStdoutStream() *StdoutStream {
return &StdoutStream{
stdout: os.Stdout,
}
}
func (self *StdoutStream) Tell() (int64, error) {
// Stdout.Stat().Size() always return 0
return 0, nil
}
func (self *StdoutStream) Write(s string) error {
_, err := self.stdout.WriteString(s)
return err
}
func (self *StdoutStream) Flush() error {
// Empty body
return nil
}
func (self *StdoutStream) Close() error {
// Don't close stdout
return nil
}
type StdoutHandler struct {
*StreamHandler
}
func NewStdoutHandler() *StdoutHandler {
stream := NewStdoutStream()
handler := NewStreamHandler("stdout", LevelNotset, stream)
object := &StdoutHandler{
StreamHandler: handler,
}
Closer.RemoveHandler(object.StreamHandler)
Closer.AddHandler(object)
return object
}
func (self *StdoutHandler) Emit(record *LogRecord) error {
return self.StreamHandler.Emit2(self, record)
}
func (self *StdoutHandler) Handle(record *LogRecord) int {
return self.Handle2(self, record)
}
func (self *StdoutHandler) Close() {
self.StreamHandler.Close2()
}