-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathlog_test.go
More file actions
60 lines (52 loc) · 1.21 KB
/
log_test.go
File metadata and controls
60 lines (52 loc) · 1.21 KB
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
package vncproxy
import (
"fmt"
"log"
"testing"
)
func TestNewLogger(t *testing.T) {
l := NewLogger(DebugLevel, nil)
l.Infof("info message")
l.Debugf("debug message")
}
type myLogger struct {
Format string
Msg string
}
func (l *myLogger) Infof(format string, v ...interface{}) {
l.Format = format
l.Msg = fmt.Sprintf("%v", v...)
log.Printf(format, v...)
}
func (l *myLogger) Debugf(format string, v ...interface{}) {
l.Format = format
l.Msg = fmt.Sprintf("%s", v...)
log.Printf(format, v...)
}
func TestNewCustomLogger(t *testing.T) {
_logger := &myLogger{}
l := NewLogger(DebugLevel, _logger)
fn1 := []func(...interface{}){l.Info, l.Debug}
for i, f := range fn1 {
msg := fmt.Sprintf("some messages %d", i)
f(msg)
if _logger.Format != "[vncproxy] %v" {
t.Fatal("incorrect logger format")
}
if _logger.Msg != msg {
t.Fatal("incorrect logger msg")
}
}
fn2 := []func(string, ...interface{}){l.Infof, l.Debugf}
format := "prefix %v"
for i, f := range fn2 {
msg := fmt.Sprintf("some messages %d", i)
f(format, msg)
if _logger.Format != "[vncproxy] %v" {
t.Fatal("incorrect logger format")
}
if _logger.Msg != fmt.Sprintf(format, msg) {
t.Fatal("incorrect logger msg")
}
}
}