-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlogging.go
46 lines (37 loc) · 1002 Bytes
/
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
package controller
// see https://github.com/cihub/seelog-examples/blob/master/library/lib_log.go
import (
"errors"
seelog "github.com/cihub/seelog"
"io"
)
var logger seelog.LoggerInterface
func init() {
DisableLog()
}
// DisableLog disables all library log output
func DisableLog() {
logger = seelog.Disabled
}
// UseLogger uses a specified seelog.LoggerInterface to output library log.
// Use this func if you are using Seelog logging system in your app.
func UseLogger(newLogger seelog.LoggerInterface) {
logger = newLogger
}
// SetLogWriter uses a specified io.Writer to output library log.
// Use this func if you are not using Seelog logging system in your app.
func SetLogWriter(writer io.Writer) error {
if writer == nil {
return errors.New("Nil writer")
}
newLogger, err := seelog.LoggerFromWriterWithMinLevel(writer, seelog.TraceLvl)
if err != nil {
return err
}
UseLogger(newLogger)
return nil
}
// Call this before app shutdown
func FlushLog() {
logger.Flush()
}