This repository has been archived by the owner on Jan 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
gologger_test.go
83 lines (77 loc) · 2.19 KB
/
gologger_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
package gologger
import (
"fmt"
"github.com/stretchr/testify/assert"
"os"
"testing"
//elastigo "github.com/mattbaird/elastigo/lib"
)
func TestSimpleConsole(t *testing.T) {
log := GetLogger(CONSOLE, SimpleLog)
assert.NotNil(t, log)
assert.Equal(t, "console", log.Logger.PrinterType)
assert.Equal(t, "simple", log.Logger.Location)
log.Message("Message Log")
log.Warn("Warring Log")
log.Debug("Debug Log")
log.Info("Info Log")
log.Error("Error Log")
log.Log("Log Log")
fmt.Println()
}
func TestColorConsole(t *testing.T) {
log := GetLogger(CONSOLE, ColoredLog)
assert.NotNil(t, log)
assert.Equal(t, "console", log.Logger.PrinterType)
assert.Equal(t, "color", log.Logger.Location)
log.Message("Message Log")
log.Warn("Warring Log")
log.Debug("Debug Log")
log.Info("Info Log")
log.Error("Error Log")
log.Log("Log Log")
fmt.Println()
}
func TestDefaultFileLog(t *testing.T) {
defaultFileLog := GetLogger(FILE, "")
assert.NotNil(t, defaultFileLog)
defaultFileLog.Log("Test File Log")
file, err := os.Stat("log.txt")
assert.Nil(t, err)
assert.Equal(t, file.Name(), "log.txt")
initFileSize := file.Size()
defaultFileLog.Log("Second Line")
file, err = os.Stat("log.txt")
afterFileSize := file.Size()
assert.NotEqual(t, initFileSize, afterFileSize)
os.Remove("log.txt")
}
func TestFileLog(t *testing.T) {
fileLog := GetLogger(FILE, "customfolder/customlog.txt")
assert.NotNil(t, fileLog)
fileLog.Log("Test File Log")
file, err := os.Stat("customfolder/customlog.txt")
assert.Nil(t, err)
assert.Equal(t, file.Name(), "customlog.txt")
initFileSize := file.Size()
fileLog.Log("Second Line")
file, err = os.Stat("customfolder/customlog.txt")
afterFileSize := file.Size()
assert.NotEqual(t, initFileSize, afterFileSize)
os.RemoveAll("customfolder/customlog.txt")
}
/*
func TestEsLog(t *testing.T) {
esLog := GetLogger(ELASTICSEARCH, "http://localhost:9200/customlogindex")
assert.NotNil(t, esLog)
assert.Equal(t, esLog.Logger.PrinterType, "es")
esLog.Log("Log Into ES")
client := elastigo.NewConn()
client.SetFromUrl("http://localhost:9200")
hits, err := client.Search("customlogindex", "", nil, nil)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
assert.NotEqual(t, hits.Hits.Hits, 0)
}*/