This repository has been archived by the owner on Oct 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.go
73 lines (64 loc) · 1.79 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
63
64
65
66
67
68
69
70
71
72
73
package main
import (
"log"
"os"
"strings"
"time"
"github.com/Sirupsen/logrus"
)
func initLogger() {
allowedTimestampsFormat := map[string]int{
"Mon Jan _2 15:04:05 2006": 1,
"Mon Jan _2 15:04:05 MST 2006": 1,
"Mon Jan 02 15:04:05 -0700 2006": 1,
"02 Jan 06 15:04 MST": 1,
"02 Jan 06 15:04 -0700": 1,
"Monday, 02-Jan-06 15:04:05 MST": 1,
"Mon, 02 Jan 2006 15:04:05 MST": 1,
"Mon, 02 Jan 2006 15:04:05 -0700": 1,
"2006-01-02T15:04:05Z07:00": 1,
"2006-01-02T15:04:05.999999999Z07:00": 1,
"3:04PM": 1,
"Jan _2 15:04:05": 1,
"Jan _2 15:04:05.000": 1,
"Jan _2 15:04:05.000000": 1,
"Jan _2 15:04:05.000000000": 1,
}
_, ok := allowedTimestampsFormat[Configs.Log.TimestampFormat]
if ok == false {
logPrintln("Wrong Timestamp Format value in config!")
time.Sleep(10 * time.Millisecond)
abstractExitFunction(1)
}
var formatter logrus.Formatter
switch strings.ToLower(Configs.Log.Formatter) {
case "text":
formatter = &logrus.TextFormatter{FullTimestamp: true, DisableColors: Configs.Log.DisableColors, TimestampFormat: Configs.Log.TimestampFormat}
break
case "json":
formatter = &logrus.JSONFormatter{TimestampFormat: Configs.Log.TimestampFormat}
break
default:
logPrintln("Error Log config formatter")
time.Sleep(10 * time.Millisecond)
abstractExitFunction(1)
break
}
level, err := logrus.ParseLevel(Configs.Log.LogLevel)
if err != nil {
logPrintln(err)
time.Sleep(10 * time.Millisecond)
abstractExitFunction(1)
}
Logger = &logrus.Logger{
Out: os.Stdout,
Formatter: formatter,
Level: level,
}
}
func logPrintln(args ...interface{}) {
isTesting := os.Getenv("TESTING")
if isTesting != "YES" {
log.Println(args)
}
}