forked from morita-kuma/golog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger_test.go
158 lines (134 loc) · 3.33 KB
/
logger_test.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package golog
import (
"testing"
"fmt"
"os"
"log"
)
func TestNewLogger(t *testing.T) {
func () {
logger := NewLogger("testLogger", LogLevel_TRACE)
appender := NewByteBufferAppender()
logger.SetAppender(appender)
logger.Debug("my first logger0")
logger.Debug("my first logger1")
logger.Debug("my first logger2")
logger.Debug("my first logger3")
fmt.Println(appender.String())
}()
func () {
logger := NewLogger("testLogger", LogLevel_TRACE)
logger.SetAppender(ConsoleAppender{destination:Destination_STDERR})
logger.Debug("hogehoge")
}()
// os.Stdout
func () {
logger := NewLogger("testLogger", LogLevel_TRACE)
logger.SetAppender(os.Stdout)
logger.Debug("fugafuga\n")
}()
// os.File
func () {
f, err := os.Create("./log/dat2")
if err != nil {
fmt.Print(err)
}
logger := NewLogger("testLogger", LogLevel_TRACE)
logger.SetAppender(f)
logger.Debug("write to file1\n")
logger.Debug("write to file2\n")
logger.Debug("write to file3\n")
}()
func () {
logger := NewLogger("testLogger", LogLevel_TRACE)
appender := NewByteBufferAppender()
logger.SetAppender(appender)
logger.SInfo(&JsonLogEvent{
event: struct{
Name string `json:"name"`
Address string `json:"address"`
}{
Name:"name_value",
Address:"address_value",
},
})
fmt.Println(appender.String())
}()
func () {
logger := NewLogger("testLogger",LogLevel_TRACE)
logger.SetAppender(NewDefaultConsoleAppender(), NewDefaultConsoleAppender())
logger.Tracef("value = %v", 10)
}()
}
func TestNewAsyncFileAppender(t *testing.T) {
appender,_ := NewFileAppender("./log/dat2")
logger := NewDefaultLogger()
logger.SetAppender(appender)
logger.Info("x")
}
func BenchmarkLogger_Info_ontime(b *testing.B) {
f, err := os.Create("./log/dat1")
if err != nil {
fmt.Print(err)
}
logger := NewDefaultLogger()
logger.SetAppender(f)
data := "abcdefghijklmn"
for i := 0; i < b.N; i++ {
logger.Info(data)
}
}
func BenchmarkLogger_Json_to_buffer(b *testing.B) {
appender,_ := NewFileAppender("./log/dat2")
logger := NewDefaultLogger()
logger.SetAppender(appender)
logger.DisableLogEventMetadata()
obj := struct {
Name string `json:"name"`
Address string `json:"address"`
}{
Name: "name",
Address: "address",
}
for i := 0; i< b.N; i++ {
logger.Infoj(obj)
}
}
func BenchmarkLogger_text_to_buffer(b *testing.B) {
appender,_ := NewFileAppender("./log/fuga")
logger := NewDefaultLogger()
logger.SetAppender(appender)
logger.DisableLogEventMetadata()
for i := 0; i< b.N; i++ {
logger.doAppendIfLevelEnabled(&TextLogEvent{Event:"ssss"}, nil, LogLevel_INFO)
}
}
func BenchmarkLogger_text_to_buffer2(b *testing.B) {
appender,_ := NewFileAppender("./log/dat2")
logger := NewDefaultLogger()
logger.SetAppender(appender)
logger.DisableLogEventMetadata()
for i := 0; i< b.N; i++ {
logger.Info("hoge")
}
}
func BenchmarkLogger_text_to_buffer3(b *testing.B) {
appender,_ := NewFileAppender("./log/dat3")
logger := NewDefaultLogger()
logger.SetAppender(appender)
logger.SetMetadataConfig(&MetadataConfig{
IsEnabledLogLevel: true,
IsEnabledLoggerName: true,
IsEnabledTime: true,
})
for i := 0; i< b.N; i++ {
logger.Info("hoge")
}
}
func BenchmarkLogger_default(b *testing.B) {
appender,_ := NewFileAppender("./log/dat_x")
log.SetOutput(appender)
for i :=0; i<b.N; i++ {
log.Print("xxxxxxx")
}
}