-
Notifications
You must be signed in to change notification settings - Fork 56
/
logMan.go
42 lines (33 loc) · 840 Bytes
/
logMan.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
// logMan controls if log action should really be performed by `canLog()`
// It also provides utility functions to accept other data format rather than []byte,
// e.g. `logString()` accepts string as log data.
package serverLog
import "os"
type logMan chan<- []byte
func (lMan logMan) canLog() bool {
return lMan != nil
}
func (lMan logMan) log(payload []byte) {
if lMan.canLog() {
lMan <- payload
}
}
func (lMan logMan) logString(payload string) {
lMan.log([]byte(payload))
}
func newLogMan(fMan *FileMan, fsPath string, dashFile *os.File) (logMan, error) {
var ch chan<- []byte
var err error
if len(fsPath) > 0 {
if fsPath == "-" {
ch, err = fMan.getWritingCh("", dashFile)
} else {
ch, err = fMan.getWritingCh(fsPath, nil)
}
if err != nil {
return nil, err
}
}
man := logMan(ch)
return man, nil
}