-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.go
96 lines (76 loc) · 1.83 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package logger
import (
// "fmt"
"os"
"time"
log "github.com/sirupsen/logrus"
)
// type StandardField struct {
// Name string
// Msg string
// Time time.Time
// // "name": name,
// // "msg": msg,
// // "time": time,
// }
// var (
// InfoLogger *log.Logger
// ErrorLogger *log.Logger
// )
var logging = log.New()
// type StandardField struct{
// Name string
// Msg string
// Time time.Time
// }
// type LogFields struct {
// s *StandardField[]string
// }
// var s *StandardField
// var requestLogger = log.WithFields(log.Fields{"Name: ": s.Name, "Msg: ": s.Msg, "Time: ": s.Time})
// func Fields(name string, msg string, time time.Time) *log.Fields{
// log.SetFormatter(&log.JSONFormatter{})
// standardFields := log.Fields{
// // "Name": s.Name,
// // "Msg": s.Msg,
// // "Time": s.Time,
// }
// log.WithFields(standardFields)
// return &standardFields
// }
//Stand: 23.09.2020
//SetOutputFile ...
func SetOutputFile(loggingTo string) {
logFile, err := os.OpenFile(loggingTo, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
logging.Out = os.Stdout
CheckErr(err)
logging.Out = logFile
}
// // InfoLog makes new Info-Level Input in logfile
// func (s *StandardField) InfoLog(name string, msg string) {
// // log.Println(InfoLoggerName)
// }
// //ErrorLog makes new Error-Level input in logfile
// func ErrorLog(err error) {
// if err != nil {
// // log.NewEntry(ErrorLogger).Error()
// }
// }
// Stand 24.09.2020
// Formatter ...
func Formatter(a bool, colours bool){
formatter := new(log.TextFormatter)
formatter.TimestampFormat = time.Now().Format(time.RFC1123)
formatter.FullTimestamp = a
formatter.ForceColors = colours
log.SetFormatter(formatter)
}
func LevelInfo(msg string, name string) {
log.Info("Job: "+name, "; Msg: "+msg)
}
// CheckErr ...
func CheckErr(err error) {
if err != nil {
panic(err)
}
}