|
@@ -0,0 +1,42 @@
|
|
1
|
+package main
|
|
2
|
+
|
|
3
|
+import (
|
|
4
|
+ "os"
|
|
5
|
+
|
|
6
|
+ "github.com/sirupsen/logrus"
|
|
7
|
+)
|
|
8
|
+
|
|
9
|
+type utcFormatter struct {
|
|
10
|
+ logrus.Formatter
|
|
11
|
+}
|
|
12
|
+
|
|
13
|
+func (f utcFormatter) Format(entry *logrus.Entry) ([]byte, error) {
|
|
14
|
+ entry.Time = entry.Time.UTC()
|
|
15
|
+ return f.Formatter.Format(entry)
|
|
16
|
+}
|
|
17
|
+
|
|
18
|
+func logConfig() error {
|
|
19
|
+ var disableColors = false
|
|
20
|
+
|
|
21
|
+ if len(*logFile) > 0 {
|
|
22
|
+ f, err := os.OpenFile(*logFile, os.O_WRONLY|os.O_CREATE, 0755)
|
|
23
|
+ if err != nil {
|
|
24
|
+ return err
|
|
25
|
+ }
|
|
26
|
+ logrus.SetOutput(f)
|
|
27
|
+
|
|
28
|
+ disableColors = true
|
|
29
|
+ }
|
|
30
|
+
|
|
31
|
+ logrus.SetFormatter(&utcFormatter{
|
|
32
|
+ &logrus.TextFormatter{
|
|
33
|
+ TimestampFormat: "2006-01-02T15:04:05.000000000Z07:00",
|
|
34
|
+ FullTimestamp: true,
|
|
35
|
+ DisableColors: disableColors,
|
|
36
|
+ DisableTimestamp: false,
|
|
37
|
+ DisableSorting: false,
|
|
38
|
+ },
|
|
39
|
+ })
|
|
40
|
+
|
|
41
|
+ return nil
|
|
42
|
+}
|