-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.go
62 lines (51 loc) · 1.48 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
53
54
55
56
57
58
59
60
61
62
package main
import (
"flag"
"os"
"github.com/sirupsen/logrus"
)
var (
confFile *string
logFile *string
respawnTimeout *int64
keepAlive *int64
backLog *bool
logLevel *string
promPort *string
cpuprofile *string
logger *logrus.Logger
)
func init() {
confFile = flag.String("C", "/etc/test/gpstrack.yaml", "config file full path")
logFile = flag.String("L", "stdout", "log file path or stdout")
keepAlive = flag.Int64("K", 5, "keepalive interval, sec")
respawnTimeout = flag.Int64("R", 10, "respawn interval, sec")
backLog = flag.Bool("b", false, "read backloged messages(bugged)")
logLevel = flag.String("l", "info", "logging level (info, error, critical, debug...)")
promPort = flag.String("p", "9002", "prometheus source port")
cpuprofile = flag.String("cp", "", "write cpu profile to file")
flag.Parse()
logger = logrus.New()
formatter := &logrus.TextFormatter{
FullTimestamp: true,
TimestampFormat: "2006-01-02T15:04:05-07:00",
DisableColors: false,
}
logger.Formatter = formatter
ll, err := logrus.ParseLevel(*logLevel)
if err != nil {
ll = logrus.InfoLevel
}
logger.SetLevel(ll)
if *logFile != "stdout" {
// prepare log file
handle, err := os.OpenFile(*logFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
logger.WithFields(logrus.Fields{"logFile": logFile}).Fatalf("%+v", err)
}
logger.Out = handle
} else {
logger.Out = os.Stdout
}
//logger.Println(*confFile, *logFile)
}