forked from mushorg/glutton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.go
52 lines (44 loc) · 1.13 KB
/
logger.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
package glutton
import (
"errors"
"strconv"
"github.com/Unknwon/com"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
func initLogger(logPath *string, id string, debug *string) (*zap.Logger, error) {
var cfg zap.Config
if !com.IsDir(*logPath) {
cfg = zap.NewProductionConfig()
cfg.ErrorOutputPaths = []string{*logPath + ".err"}
cfg.OutputPaths = []string{*logPath}
} else {
err := errors.New("[glutton ] file name is missing in log path")
return nil, err
}
cfg.InitialFields = map[string]interface{}{
"sensorID": id,
}
checkDebug, err := strconv.ParseBool(*debug)
if err != nil {
return nil, err
}
if checkDebug {
cfg.Level.SetLevel(zapcore.DebugLevel)
}
logger, err := cfg.Build()
return logger, err
}
// TODO: add connection information to log message
/*
func (g *Glutton) addFeilds(srcHost, srcPort, dstHost, rule string, dstPort uint16, connKey [2]uint64) *zap.Logger {
return g.logger.WithOptions(zap.Fields(
zap.String("srcHost", srcHost),
zap.String("srcPort", srcPort),
zap.String("dstHost", dstHost),
zap.Uint16("dstPort", dstPort),
zap.String("rule", rule),
zap.Any("connKey", connKey),
))
}
*/