forked from stamp/goADS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.go
45 lines (36 loc) · 980 Bytes
/
log.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
package goADS
import (
seelog "github.com/cihub/seelog"
"io"
"errors"
)
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()
}