forked from kylelemons/log4go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
log4go_test.go
601 lines (530 loc) · 18.5 KB
/
log4go_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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
// Copyright (C) 2010, Kyle Lemons <[email protected]>. All rights reserved.
package log4go
import (
"crypto/md5"
"encoding/hex"
"fmt"
"io"
"io/ioutil"
"os"
"runtime"
"testing"
"time"
)
const testLogFile = "_logtest.log"
var now time.Time = time.Unix(0, 1234567890123456789).In(time.UTC)
func newLogRecord(lvl level, src string, msg string) *LogRecord {
return &LogRecord{
Level: lvl,
Source: src,
Created: now,
Message: msg,
}
}
func TestELog(t *testing.T) {
fmt.Printf("Testing %s\n", L4G_VERSION)
lr := newLogRecord(CRITICAL, "source", "message")
if lr.Level != CRITICAL {
t.Errorf("Incorrect level: %d should be %d", lr.Level, CRITICAL)
}
if lr.Source != "source" {
t.Errorf("Incorrect source: %s should be %s", lr.Source, "source")
}
if lr.Message != "message" {
t.Errorf("Incorrect message: %s should be %s", lr.Source, "message")
}
}
var formatTests = []struct {
Test string
Record *LogRecord
Formats map[string]string
}{
{
Test: "Standard formats",
Record: &LogRecord{
Level: ERROR,
Source: "source",
Message: "message",
Created: now,
},
Formats: map[string]string{
// TODO(kevlar): How can I do this so it'll work outside of PST?
FORMAT_DEFAULT: "[2009/02/13 23:31:30 UTC] [EROR] (source) message\n",
FORMAT_SHORT: "[23:31 02/13/09] [EROR] message\n",
FORMAT_ABBREV: "[EROR] message\n",
},
},
}
func TestFormatLogRecord(t *testing.T) {
for _, test := range formatTests {
name := test.Test
for fmt, want := range test.Formats {
if got := FormatLogRecord(fmt, test.Record); got != want {
t.Errorf("%s - %s:", name, fmt)
t.Errorf(" got %q", got)
t.Errorf(" want %q", want)
}
}
}
}
var logRecordWriteTests = []struct {
Test string
Record *LogRecord
Console string
}{
{
Test: "Critical message",
Record: &LogRecord{
Level: CRITICAL,
Source: "source",
Message: "message",
Created: now,
},
Console: "[02/13/09 23:31:30] [CRIT] message\n",
},
{
Test: "Error message",
Record: &LogRecord{
Level: ERROR,
Source: "source",
Message: "message",
Created: now,
},
Console: "[02/13/09 23:31:30] [EROR] message\n",
},
{
Test: "Normal message",
Record: &LogRecord{
Level: INFO,
Source: "source",
Message: "message",
Created: now,
},
Console: "[02/13/09 23:31:30] [INFO] message\n",
},
}
func TestConsoleLogWriterWithoutError(t *testing.T) {
console := make(ConsoleLogWriter)
r, w := io.Pipe()
go console.runWithoutErrorWriter(w)
defer console.Close()
buf := make([]byte, 1024)
for _, test := range logRecordWriteTests {
name := test.Test
console.LogWrite(test.Record)
n, _ := r.Read(buf)
if got, want := string(buf[:n]), test.Console; got != want {
t.Errorf("%s: got %q", name, got)
t.Errorf("%s: want %q", name, want)
}
}
}
func TestConsoleLogWriterWithError(t *testing.T) {
console := make(ConsoleLogWriter)
r1, w1 := io.Pipe()
r2, w2 := io.Pipe()
go console.run(w1, w2)
defer console.Close()
buf := make([]byte, 1024)
for _, test := range logRecordWriteTests {
name := test.Test
console.LogWrite(test.Record)
if test.Record.Level == ERROR || test.Record.Level == CRITICAL {
n, _ := r2.Read(buf)
if got, want := string(buf[:n]), test.Console; got != want {
t.Errorf("%s: got %q", name, got)
t.Errorf("%s: want %q", name, want)
}
} else {
n, _ := r1.Read(buf)
if got, want := string(buf[:n]), test.Console; got != want {
t.Errorf("%s: got %q", name, got)
t.Errorf("%s: want %q", name, want)
}
}
}
}
func TestFileLogWriter(t *testing.T) {
defer func(buflen int) {
LogBufferLength = buflen
}(LogBufferLength)
LogBufferLength = 0
w := NewFileLogWriter(testLogFile, false)
if w == nil {
t.Fatalf("Invalid return: w should not be nil")
}
defer os.Remove(testLogFile)
w.LogWrite(newLogRecord(CRITICAL, "source", "message"))
w.Close()
runtime.Gosched()
if contents, err := ioutil.ReadFile(testLogFile); err != nil {
t.Errorf("read(%q): %s", testLogFile, err)
} else if len(contents) != 50 {
t.Errorf("malformed filelog: %q (%d bytes)", string(contents), len(contents))
}
}
func TestXMLLogWriter(t *testing.T) {
defer func(buflen int) {
LogBufferLength = buflen
}(LogBufferLength)
LogBufferLength = 0
w := NewXMLLogWriter(testLogFile, false)
if w == nil {
t.Fatalf("Invalid return: w should not be nil")
}
defer os.Remove(testLogFile)
w.LogWrite(newLogRecord(CRITICAL, "source", "message"))
w.Close()
runtime.Gosched()
if contents, err := ioutil.ReadFile(testLogFile); err != nil {
t.Errorf("read(%q): %s", testLogFile, err)
} else if len(contents) != 185 {
t.Errorf("malformed xmllog: %q (%d bytes)", string(contents), len(contents))
}
}
func TestLogger(t *testing.T) {
sl := NewDefaultLogger(WARNING)
if sl == nil {
t.Fatalf("NewDefaultLogger should never return nil")
}
if lw, exist := sl.filters["stdout"]; lw == nil || exist != true {
t.Fatalf("NewDefaultLogger produced invalid logger (DNE or nil)")
}
if sl.filters["stdout"].Level != WARNING {
t.Fatalf("NewDefaultLogger produced invalid logger (incorrect level)")
}
if len(sl.filters) != 1 {
t.Fatalf("NewDefaultLogger produced invalid logger (incorrect map count)")
}
//func (l *Logger) AddFilter(name string, level int, writer LogWriter) {}
l := &Logger{
filters: make(map[string]*Filter),
}
l.AddFilter("stdout", DEBUG, NewConsoleLogWriter())
if lw, exist := l.filters["stdout"]; lw == nil || exist != true {
t.Fatalf("AddFilter produced invalid logger (DNE or nil)")
}
if l.filters["stdout"].Level != DEBUG {
t.Fatalf("AddFilter produced invalid logger (incorrect level)")
}
if len(l.filters) != 1 {
t.Fatalf("AddFilter produced invalid logger (incorrect map count)")
}
//func (l *Logger) Warn(format string, args ...interface{}) error {}
if err := l.Warn("%s %d %#v", "Warning:", 1, []int{}); err.Error() != "Warning: 1 []int{}" {
t.Errorf("Warn returned invalid error: %s", err)
}
//func (l *Logger) Error(format string, args ...interface{}) error {}
if err := l.Error("%s %d %#v", "Error:", 10, []string{}); err.Error() != "Error: 10 []string{}" {
t.Errorf("Error returned invalid error: %s", err)
}
//func (l *Logger) Critical(format string, args ...interface{}) error {}
if err := l.Critical("%s %d %#v", "Critical:", 100, []int64{}); err.Error() != "Critical: 100 []int64{}" {
t.Errorf("Critical returned invalid error: %s", err)
}
// Already tested or basically untestable
//func (l *Logger) Log(level int, source, message string) {}
//func (l *Logger) Logf(level int, format string, args ...interface{}) {}
//func (l *Logger) intLogf(level int, format string, args ...interface{}) string {}
//func (l *Logger) Finest(format string, args ...interface{}) {}
//func (l *Logger) Fine(format string, args ...interface{}) {}
//func (l *Logger) Debug(format string, args ...interface{}) {}
//func (l *Logger) Trace(format string, args ...interface{}) {}
//func (l *Logger) Info(format string, args ...interface{}) {}
}
func TestLogOutput(t *testing.T) {
const (
expected = "fdf3e51e444da56b4cb400f30bc47424"
)
// Unbuffered output
defer func(buflen int) {
LogBufferLength = buflen
}(LogBufferLength)
LogBufferLength = 0
l := &Logger{
filters: make(map[string]*Filter),
}
// Delete and open the output log without a timestamp (for a constant md5sum)
l.AddFilter("file", FINEST, NewFileLogWriter(testLogFile, false).SetFormat("[%L] %M"))
defer os.Remove(testLogFile)
// Send some log messages
l.Log(CRITICAL, "testsrc1", fmt.Sprintf("This message is level %d", int(CRITICAL)))
l.Logf(ERROR, "This message is level %v", ERROR)
l.Logf(WARNING, "This message is level %s", WARNING)
l.Logc(INFO, func() string { return "This message is level INFO" })
l.Trace("This message is level %d", int(TRACE))
l.Debug("This message is level %s", DEBUG)
l.Fine(func() string { return fmt.Sprintf("This message is level %v", FINE) })
l.Finest("This message is level %v", FINEST)
l.Finest(FINEST, "is also this message's level")
l.Close()
contents, err := ioutil.ReadFile(testLogFile)
if err != nil {
t.Fatalf("Could not read output log: %s", err)
}
sum := md5.New()
sum.Write(contents)
if sumstr := hex.EncodeToString(sum.Sum(nil)); sumstr != expected {
t.Errorf("--- Log Contents:\n%s---", string(contents))
t.Fatalf("Checksum does not match: %s (expecting %s)", sumstr, expected)
}
}
func TestCountMallocs(t *testing.T) {
const N = 1
var m runtime.MemStats
getMallocs := func() uint64 {
runtime.ReadMemStats(&m)
return m.Mallocs
}
// Console logger
sl := NewDefaultLogger(INFO)
mallocs := 0 - getMallocs()
for i := 0; i < N; i++ {
sl.Log(WARNING, "here", "This is a WARNING message")
}
mallocs += getMallocs()
fmt.Printf("mallocs per sl.Log((WARNING, \"here\", \"This is a log message\"): %d\n", mallocs/N)
// Console logger formatted
mallocs = 0 - getMallocs()
for i := 0; i < N; i++ {
sl.Logf(WARNING, "%s is a log message with level %d", "This", WARNING)
}
mallocs += getMallocs()
fmt.Printf("mallocs per sl.Logf(WARNING, \"%%s is a log message with level %%d\", \"This\", WARNING): %d\n", mallocs/N)
// Console logger (not logged)
sl = NewDefaultLogger(INFO)
mallocs = 0 - getMallocs()
for i := 0; i < N; i++ {
sl.Log(DEBUG, "here", "This is a DEBUG log message")
}
mallocs += getMallocs()
fmt.Printf("mallocs per unlogged sl.Log((WARNING, \"here\", \"This is a log message\"): %d\n", mallocs/N)
// Console logger formatted (not logged)
mallocs = 0 - getMallocs()
for i := 0; i < N; i++ {
sl.Logf(DEBUG, "%s is a log message with level %d", "This", DEBUG)
}
mallocs += getMallocs()
fmt.Printf("mallocs per unlogged sl.Logf(WARNING, \"%%s is a log message with level %%d\", \"This\", WARNING): %d\n", mallocs/N)
}
func TestXMLConfig(t *testing.T) {
const (
configfile = "example.xml"
)
fd, err := os.Create(configfile)
if err != nil {
t.Fatalf("Could not open %s for writing: %s", configfile, err)
}
// This uses Fprintf instead of Fprintln because go doesn't like our formatting directives in these strings
fmt.Fprintf(fd, "%s\n", "<logging>")
fmt.Fprintf(fd, "%s\n", " <filter enabled=\"true\">")
fmt.Fprintf(fd, "%s\n", " <tag>stdout</tag>")
fmt.Fprintf(fd, "%s\n", " <type>console</type>")
fmt.Fprintf(fd, "%s\n", " <!-- level is (:?FINEST|FINE|DEBUG|TRACE|INFO|WARNING|ERROR) -->")
fmt.Fprintf(fd, "%s\n", " <level>DEBUG</level>")
fmt.Fprintf(fd, "%s\n", " </filter>")
fmt.Fprintf(fd, "%s\n", " <filter enabled=\"true\">")
fmt.Fprintf(fd, "%s\n", " <tag>file</tag>")
fmt.Fprintf(fd, "%s\n", " <type>file</type>")
fmt.Fprintf(fd, "%s\n", " <level>FINEST</level>")
fmt.Fprintf(fd, "%s\n", " <property name=\"filename\">test.log</property>")
fmt.Fprintf(fd, "%s\n", " <!--")
fmt.Fprintf(fd, "%s\n", " %T - Time (15:04:05 MST)")
fmt.Fprintf(fd, "%s\n", " %t - Time (15:04)")
fmt.Fprintf(fd, "%s\n", " %D - Date (2006/01/02)")
fmt.Fprintf(fd, "%s\n", " %d - Date (01/02/06)")
fmt.Fprintf(fd, "%s\n", " %L - Level (FNST, FINE, DEBG, TRAC, WARN, EROR, CRIT)")
fmt.Fprintf(fd, "%s\n", " %S - Source")
fmt.Fprintf(fd, "%s\n", " %M - Message")
fmt.Fprintf(fd, "%s\n", " It ignores unknown format strings (and removes them)")
fmt.Fprintf(fd, "%s\n", " Recommended: \"[%D %T] [%L] (%S) %M\"")
fmt.Fprintf(fd, "%s\n", " -->")
fmt.Fprintf(fd, "%s\n", " <property name=\"format\">[%D %T] [%L] (%S) %M</property>")
fmt.Fprintf(fd, "%s\n", " <property name=\"rotate\">false</property> <!-- true enables log rotation, otherwise append -->")
fmt.Fprintf(fd, "%s\n", " <property name=\"maxsize\">0M</property> <!-- \\d+[KMG]? Suffixes are in terms of 2**10 -->")
fmt.Fprintf(fd, "%s\n", " <property name=\"maxlines\">0K</property> <!-- \\d+[KMG]? Suffixes are in terms of thousands -->")
fmt.Fprintf(fd, "%s\n", " <property name=\"daily\">true</property> <!-- Automatically rotates when a log message is written after midnight -->")
fmt.Fprintf(fd, "%s\n", " </filter>")
fmt.Fprintf(fd, "%s\n", " <filter enabled=\"true\">")
fmt.Fprintf(fd, "%s\n", " <tag>xmllog</tag>")
fmt.Fprintf(fd, "%s\n", " <type>xml</type>")
fmt.Fprintf(fd, "%s\n", " <level>TRACE</level>")
fmt.Fprintf(fd, "%s\n", " <property name=\"filename\">trace.xml</property>")
fmt.Fprintf(fd, "%s\n", " <property name=\"rotate\">true</property> <!-- true enables log rotation, otherwise append -->")
fmt.Fprintf(fd, "%s\n", " <property name=\"maxsize\">100M</property> <!-- \\d+[KMG]? Suffixes are in terms of 2**10 -->")
fmt.Fprintf(fd, "%s\n", " <property name=\"maxrecords\">6K</property> <!-- \\d+[KMG]? Suffixes are in terms of thousands -->")
fmt.Fprintf(fd, "%s\n", " <property name=\"daily\">false</property> <!-- Automatically rotates when a log message is written after midnight -->")
fmt.Fprintf(fd, "%s\n", " </filter>")
fmt.Fprintf(fd, "%s\n", " <filter enabled=\"false\"><!-- enabled=false means this logger won't actually be created -->")
fmt.Fprintf(fd, "%s\n", " <tag>donotopen</tag>")
fmt.Fprintf(fd, "%s\n", " <type>socket</type>")
fmt.Fprintf(fd, "%s\n", " <level>FINEST</level>")
fmt.Fprintf(fd, "%s\n", " <property name=\"endpoint\">192.168.1.255:12124</property> <!-- recommend UDP broadcast -->")
fmt.Fprintf(fd, "%s\n", " <property name=\"protocol\">udp</property> <!-- tcp or udp -->")
fmt.Fprintf(fd, "%s\n", " </filter>")
fmt.Fprintf(fd, "%s\n", "</logging>")
fd.Close()
log := &Logger{
filters: make(map[string]*Filter),
}
log.LoadConfiguration(configfile)
defer os.Remove("trace.xml")
defer os.Remove("test.log")
defer log.Close()
// Make sure we got all loggers
if len(log.filters) != 3 {
t.Fatalf("XMLConfig: Expected 3 filters, found %d", len(log.filters))
}
// Make sure they're the right keys
if _, ok := log.filters["stdout"]; !ok {
t.Errorf("XMLConfig: Expected stdout logger")
}
if _, ok := log.filters["file"]; !ok {
t.Fatalf("XMLConfig: Expected file logger")
}
if _, ok := log.filters["xmllog"]; !ok {
t.Fatalf("XMLConfig: Expected xmllog logger")
}
// Make sure they're the right type
if _, ok := log.filters["stdout"].LogWriter.(ConsoleLogWriter); !ok {
t.Fatalf("XMLConfig: Expected stdout to be ConsoleLogWriter, found %T", log.filters["stdout"].LogWriter)
}
if _, ok := log.filters["file"].LogWriter.(*FileLogWriter); !ok {
t.Fatalf("XMLConfig: Expected file to be *FileLogWriter, found %T", log.filters["file"].LogWriter)
}
if _, ok := log.filters["xmllog"].LogWriter.(*FileLogWriter); !ok {
t.Fatalf("XMLConfig: Expected xmllog to be *FileLogWriter, found %T", log.filters["xmllog"].LogWriter)
}
// Make sure levels are set
if lvl := log.filters["stdout"].Level; lvl != DEBUG {
t.Errorf("XMLConfig: Expected stdout to be set to level %d, found %d", DEBUG, lvl)
}
if lvl := log.filters["file"].Level; lvl != FINEST {
t.Errorf("XMLConfig: Expected file to be set to level %d, found %d", FINEST, lvl)
}
if lvl := log.filters["xmllog"].Level; lvl != TRACE {
t.Errorf("XMLConfig: Expected xmllog to be set to level %d, found %d", TRACE, lvl)
}
// Make sure the w is open and points to the right file
if fname := log.filters["file"].LogWriter.(*FileLogWriter).file.Name(); fname != "test.log" {
t.Errorf("XMLConfig: Expected file to have opened %s, found %s", "test.log", fname)
}
// Make sure the XLW is open and points to the right file
if fname := log.filters["xmllog"].LogWriter.(*FileLogWriter).file.Name(); fname != "trace.xml" {
t.Errorf("XMLConfig: Expected xmllog to have opened %s, found %s", "trace.xml", fname)
}
// Move XML log file
os.Rename(configfile, "examples/"+configfile) // Keep this so that an example with the documentation is available
}
func BenchmarkFormatLogRecord(b *testing.B) {
const updateEvery = 1
rec := &LogRecord{
Level: CRITICAL,
Created: now,
Source: "source",
Message: "message",
}
for i := 0; i < b.N; i++ {
rec.Created = rec.Created.Add(1 * time.Second / updateEvery)
if i%2 == 0 {
FormatLogRecord(FORMAT_DEFAULT, rec)
} else {
FormatLogRecord(FORMAT_SHORT, rec)
}
}
}
func BenchmarkConsoleLog(b *testing.B) {
/* This doesn't seem to work on OS X
sink, err := os.Open(os.DevNull)
if err != nil {
panic(err)
}
if err := syscall.Dup2(int(sink.Fd()), syscall.Stdout); err != nil {
panic(err)
}
*/
stdout = ioutil.Discard
sl := NewDefaultLogger(INFO)
for i := 0; i < b.N; i++ {
sl.Log(WARNING, "here", "This is a log message")
}
}
func BenchmarkConsoleNotLogged(b *testing.B) {
sl := NewDefaultLogger(INFO)
for i := 0; i < b.N; i++ {
sl.Log(DEBUG, "here", "This is a log message")
}
}
func BenchmarkConsoleUtilLog(b *testing.B) {
sl := NewDefaultLogger(INFO)
for i := 0; i < b.N; i++ {
sl.Info("%s is a log message", "This")
}
}
func BenchmarkConsoleUtilNotLog(b *testing.B) {
sl := NewDefaultLogger(INFO)
for i := 0; i < b.N; i++ {
sl.Debug("%s is a log message", "This")
}
}
func BenchmarkFileLog(b *testing.B) {
sl := &Logger{
filters: make(map[string]*Filter),
}
b.StopTimer()
sl.AddFilter("file", INFO, NewFileLogWriter("benchlog.log", false))
b.StartTimer()
for i := 0; i < b.N; i++ {
sl.Log(WARNING, "here", "This is a log message")
}
b.StopTimer()
os.Remove("benchlog.log")
}
func BenchmarkFileNotLogged(b *testing.B) {
sl := &Logger{
filters: make(map[string]*Filter),
}
b.StopTimer()
sl.AddFilter("file", INFO, NewFileLogWriter("benchlog.log", false))
b.StartTimer()
for i := 0; i < b.N; i++ {
sl.Log(DEBUG, "here", "This is a log message")
}
b.StopTimer()
os.Remove("benchlog.log")
}
func BenchmarkFileUtilLog(b *testing.B) {
sl := &Logger{
filters: make(map[string]*Filter),
}
b.StopTimer()
sl.AddFilter("file", INFO, NewFileLogWriter("benchlog.log", false))
b.StartTimer()
for i := 0; i < b.N; i++ {
sl.Info("%s is a log message", "This")
}
b.StopTimer()
os.Remove("benchlog.log")
}
func BenchmarkFileUtilNotLog(b *testing.B) {
sl := &Logger{
filters: make(map[string]*Filter),
}
b.StopTimer()
sl.AddFilter("file", INFO, NewFileLogWriter("benchlog.log", false))
b.StartTimer()
for i := 0; i < b.N; i++ {
sl.Debug("%s is a log message", "This")
}
b.StopTimer()
os.Remove("benchlog.log")
}
// Benchmark results (darwin amd64 6g)
//elog.BenchmarkConsoleLog 100000 22819 ns/op
//elog.BenchmarkConsoleNotLogged 2000000 879 ns/op
//elog.BenchmarkConsoleUtilLog 50000 34380 ns/op
//elog.BenchmarkConsoleUtilNotLog 1000000 1339 ns/op
//elog.BenchmarkFileLog 100000 26497 ns/op
//elog.BenchmarkFileNotLogged 2000000 821 ns/op
//elog.BenchmarkFileUtilLog 50000 33945 ns/op
//elog.BenchmarkFileUtilNotLog 1000000 1258 ns/op