-
Notifications
You must be signed in to change notification settings - Fork 0
/
all_test.go
73 lines (62 loc) · 1.65 KB
/
all_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
// ---------------------------------------------------------------------------
//
// all_test.go
//
// Copyright (c) 2014, Jared Chavez.
// All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//
// -----------
package flog
import (
"fmt"
"os"
"testing"
"time"
)
// TestLog creates a new log, writes a few entries to it, rotates the log,
// and then closes it out. At the end of the test two files should exist:
// logs/info.log and logs/old/<date>-info.log
func TestLog(t *testing.T) {
iLog := New("info", "./logs", BufferedFile)
eLog := New("error", "./logs", DirectFile)
iLog.Print("this is a new INFO log")
eLog.Print("this is a new ERROR log")
iLog.Print("testing %s", "123")
eLog.Print("testing %s", "456")
iLog.Print("testing %s", "789")
iLog.Print("testing decimal: %d", 123)
iLog.Print("testing bool: %t", false)
iLog.Print("testing float: %f", 123.456)
iLog = Rotate(iLog)
eLog = Rotate(eLog)
iLog.Print("testing 123 **after** rotate")
eLog.Print("testing 456 after rotate")
iLog.Close()
eLog.Close()
now := time.Now()
newPath := fmt.Sprintf(
"logs/old/%d%d%d-",
now.Year(),
now.Month(),
now.Day(),
)
_, err := os.Stat("logs/info.log")
if err != nil {
t.Error(err)
}
_, err = os.Stat("logs/error.log")
if err != nil {
t.Error(err)
}
_, err = os.Stat(newPath + "info.log")
if err != nil {
t.Error(err)
}
_, err = os.Stat(newPath + "error.log")
if err != nil {
t.Error(err)
}
}