Repository navigation
Expand file tree
/
Copy pathlog.go
More file actions
151 lines (124 loc) · 3.59 KB
/
Copy pathlog.go
File metadata and controls
151 lines (124 loc) · 3.59 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package log
import (
"fmt"
"io"
"github.com/sirupsen/logrus"
)
// F the log fields
type F map[string]interface{}
// Entry the log entry
type Entry struct {
*logrus.Entry
}
// Level type
type Level uint32
// Format type
type Format uint32
const (
// JSON JSON Format
JSON Format = iota
// TEXT Text Format
TEXT = 1 // 1
)
// These are the different logging levels. You can set the logging level to log
// on your instance of logger, obtained with `logrus.New()`.
const (
// PanicLevel level, highest level of severity. Logs and then calls panic with the
// message passed to Debug, Info, ...
PanicLevel Level = iota
// FatalLevel level. Logs and then calls `logger.Exit(1)`. It will exit even if the
// logging level is set to Panic.
FatalLevel
// ErrorLevel level. Logs. Used for errors that should definitely be noted.
// Commonly used for hooks to send errors to an error tracking service.
ErrorLevel
// WarnLevel level. Non-critical entries that deserve eyes.
WarnLevel
// InfoLevel level. General operational entries about what's going on inside the
// application.
InfoLevel
// DebugLevel level. Usually only enabled when debugging. Very verbose logging.
DebugLevel
// TraceLevel level. Designates finer-grained informational events than the Debug.
TraceLevel
)
// SetFormatter 0=JSON, 1=TEXT
func SetFormatter(format Format) {
if format == JSON {
logrus.SetFormatter(&logrus.JSONFormatter{})
} else if format == TEXT {
logrus.SetFormatter(&logrus.TextFormatter{})
}
}
// SetOutput log writer
func SetOutput(out io.Writer) {
logrus.SetOutput(out)
}
// SetLevel log level
func SetLevel(level Level) {
logrus.SetLevel(logrus.Level(level))
}
// GetLevel get log level
func GetLevel() Level {
return Level(logrus.GetLevel())
}
// With fields
func With(fields F) *Entry {
return &Entry{logrus.WithFields(logrus.Fields(fields))}
}
// Trace trace log
func (entry *Entry) Trace(message string, v ...interface{}) {
entry.Entry.Trace(fmt.Sprintf(message, v...))
}
// Trace trace log
func Trace(message string, v ...interface{}) {
logrus.Trace(fmt.Sprintf(message, v...))
}
// Debug debug log
func (entry *Entry) Debug(message string, v ...interface{}) {
entry.Entry.Debug(fmt.Sprintf(message, v...))
}
// Debug debug log
func Debug(message string, v ...interface{}) {
logrus.Debug(fmt.Sprintf(message, v...))
}
// Info info log
func (entry *Entry) Info(message string, v ...interface{}) {
entry.Entry.Info(fmt.Sprintf(message, v...))
}
// Info info log
func Info(message string, v ...interface{}) {
logrus.Info(fmt.Sprintf(message, v...))
}
// Warn warn log
func (entry *Entry) Warn(message string, v ...interface{}) {
entry.Entry.Warn(fmt.Sprintf(message, v...))
}
// Warn warn log
func Warn(message string, v ...interface{}) {
logrus.Warn(fmt.Sprintf(message, v...))
}
// Error error log
func (entry *Entry) Error(message string, v ...interface{}) {
entry.Entry.Error(fmt.Sprintf(message, v...))
}
// Error error log
func Error(message string, v ...interface{}) {
logrus.Error(fmt.Sprintf(message, v...))
}
// Fatal fatal log Calls os.Exit(1) after logging
func (entry *Entry) Fatal(message string, v ...interface{}) {
entry.Entry.Fatal(fmt.Sprintf(message, v...))
}
// Fatal fatal log Calls os.Exit(1) after logging
func Fatal(message string, v ...interface{}) {
logrus.Fatal(fmt.Sprintf(message, v...))
}
// Panic panic log Calls panic() after logging
func (entry *Entry) Panic(message string, v ...interface{}) {
entry.Entry.Panic(fmt.Sprintf(message, v...))
}
// Panic panic log Calls panic() after logging
func Panic(message string, v ...interface{}) {
logrus.Panic(fmt.Sprintf(message, v...))
}
You can’t perform that action at this time.