-
Notifications
You must be signed in to change notification settings - Fork 1
/
logging.go
63 lines (49 loc) · 1.13 KB
/
logging.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
package vv104
import (
"fmt"
"log"
)
var (
LogChan chan string
logDebug *log.Logger
logError *log.Logger
logInfo *log.Logger
vv104loggerDebug vv104logger
vv104loggerError vv104logger
vv104loggerInfo vv104logger
)
type vv104logger struct {
logToChan bool
logToStdOut bool
}
func (vvlog vv104logger) Write(p []byte) (n int, err error) {
if vvlog.logToChan {
// addLogEntry(string(p))
LogChan <- string(p)
}
if vvlog.logToStdOut {
n, err = fmt.Print(string(p))
}
return n, err
}
func NewLogChan() chan string {
LogChan = make(chan string, 50)
return LogChan
}
func initLogger(config Config) {
vv104loggerDebug = vv104logger{
logToChan: config.LogToBuffer,
logToStdOut: config.LogToStdOut,
}
vv104loggerError = vv104logger{
logToChan: config.LogToBuffer,
logToStdOut: config.LogToStdOut,
}
vv104loggerInfo = vv104logger{
logToChan: config.LogToBuffer,
logToStdOut: config.LogToStdOut,
}
logDebug = log.New(vv104loggerDebug, "Debug: ", log.Ltime|log.Lshortfile)
logError = log.New(vv104loggerError, "ERROR: ", log.Ltime|log.Lshortfile)
logInfo = log.New(vv104loggerInfo, "", log.Ltime)
}