-
Notifications
You must be signed in to change notification settings - Fork 1
/
scope_test.go
54 lines (34 loc) · 818 Bytes
/
scope_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
package logger
import (
"bytes"
"testing"
"time"
. "gopkg.in/check.v1"
)
// Hook up gocheck into the "go test" runner.
func Test(t *testing.T) { TestingT(t) }
type ScopeSuite struct{}
var _ = Suite(&ScopeSuite{})
func (s *ScopeSuite) TestScopeLogger(c *C) {
var out bytes.Buffer
scope := NewScope(&out, "test", DEBUG)
scope.Info("INFOLN")
time.Sleep(100 * time.Millisecond)
scope.Debug("DEBUG")
scope.Errorf("ERRORF -> %d", 1)
time.Sleep(200 * time.Millisecond)
scope.SetLevel(WARNING)
scope.Debug("DEBUG")
scope.SetFlags(LstdFlags | Lshortfile)
scope.Errorf("ERRORF -> %d", 2)
c.Assert(scope.Flush(), IsNil)
o := out.String()
c.Log(o)
c.Assert(o[20:], Equals,
`test
[I] +0ms INFOLN
[D] +100ms DEBUG
[E] +100ms ERRORF -> 1
[E] +300ms scope_test.go:39: ERRORF -> 2
`)
}