forked from morita-kuma/golog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
appender_console.go
49 lines (39 loc) · 1004 Bytes
/
appender_console.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
package golog
import (
"os"
)
type Destination string
const Destination_STDOUT = "STDOUT"
const Destination_STDERR = "STDERR"
// ConsoleAppender
type ConsoleAppender struct {
destination Destination
}
// Write implements io.Writer
func (appender ConsoleAppender) Write(data []byte) (n int, err error) {
data = append(data, []byte("\n")...)
switch appender.destination {
case Destination_STDERR :
os.Stderr.Write(data)
case Destination_STDOUT :
os.Stdout.Write(data)
default:
os.Stdout.Write(data)
}
return 0,nil
}
// Close implements io.Closer
func (appender ConsoleAppender) Close() error {
return nil
}
// NewDefaultConsoleAppender returns new ConsoleAppender
// default io.writer is used to os.Stdout
func NewDefaultConsoleAppender() ConsoleAppender {
return NewConsoleAppender(Destination_STDOUT)
}
// NewConsoleAppender returns new ConsoleAppender
func NewConsoleAppender(destination Destination) ConsoleAppender {
return ConsoleAppender{
destination: destination,
}
}