-
Notifications
You must be signed in to change notification settings - Fork 1
/
exported.go
215 lines (176 loc) · 5.92 KB
/
exported.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
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
// This file is part of graze/golang-service
//
// Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com>
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
//
// license: https://github.com/graze/golang-service/blob/master/LICENSE
// link: https://github.com/graze/golang-service
package log
import (
"context"
"io"
"github.com/Sirupsen/logrus"
)
// 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 logrus.Level = iota
// FatalLevel level. Logs and then calls `os.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
)
// SetOutput sets the standard logger output.
func SetOutput(out io.Writer) {
logEntry.SetOutput(out)
}
// SetFormatter sets the standard logger formatter.
func SetFormatter(formatter logrus.Formatter) {
logEntry.SetFormatter(formatter)
}
// SetLevel sets the standard logger level.
func SetLevel(level logrus.Level) {
logEntry.SetLevel(level)
}
// Level returns the standard logger level.
func Level() logrus.Level {
return logEntry.Level()
}
// AddHook adds a new hook to the global logging context
func AddHook(hook logrus.Hook) {
logEntry.AddHook(hook)
}
// With returns a new LoggerEntry with the supplied fields
func With(fields KV) FieldLogger {
return logEntry.With(fields)
}
// Err creates a new LoggerEntry from the standard logger and adds an error
// to it, using the value defined in ErrorKey as key.
func Err(err error) FieldLogger {
return logEntry.Err(err)
}
// Fields will return the current set of fields in the global context
func Fields() KV {
return logEntry.Fields()
}
// Ctx will use the provided context with its logs if applicable
func Ctx(ctx context.Context) FieldLogger {
return logEntry.Ctx(ctx)
}
// NewContext adds the current `logEntry` into `ctx`
func NewContext(ctx context.Context) context.Context {
return logEntry.NewContext(ctx)
}
// AppendContext creates a new context.Context from the supplied ctx with the fields appended to the end
func AppendContext(ctx context.Context, fields KV) context.Context {
return logEntry.AppendContext(ctx, fields)
}
// Debug logs a message at level Debug on the standard logger.
func Debug(args ...interface{}) {
logEntry.Debug(args...)
}
// Info logs a message at level Info on the standard logger.
func Info(args ...interface{}) {
logEntry.Info(args...)
}
// Print logs a message at level Info on the standard logger.
func Print(args ...interface{}) {
logEntry.Print(args...)
}
// Warn logs a message at level Warning on the standard logger.
func Warn(args ...interface{}) {
logEntry.Warn(args...)
}
// Warning logs a message at level Warning on the standard logger.
func Warning(args ...interface{}) {
logEntry.Warning(args...)
}
// Error logs a message at level Error on the standard logger.
func Error(args ...interface{}) {
logEntry.Error(args...)
}
// Fatal logs a message at level Fatal on the standard logger
func Fatal(args ...interface{}) {
logEntry.Fatal(args)
}
// Panic logs a message at level Panic on the standard logger
func Panic(args ...interface{}) {
logEntry.Panic(args)
}
// Debugf logs a message at level Debug on the standard logger.
func Debugf(format string, args ...interface{}) {
logEntry.Debugf(format, args...)
}
// Infof logs a message at level Info on the standard logger.
func Infof(format string, args ...interface{}) {
logEntry.Infof(format, args...)
}
// Printf logs a message at level Info on the standard logger.
func Printf(format string, args ...interface{}) {
logEntry.Printf(format, args...)
}
// Warnf logs a message at level Warning on the standard logger.
func Warnf(format string, args ...interface{}) {
logEntry.Warnf(format, args...)
}
// Warningf logs a message at level Warning on the standard logger.
func Warningf(format string, args ...interface{}) {
logEntry.Warningf(format, args...)
}
// Errorf logs a message at level Error on the standard logger.
func Errorf(format string, args ...interface{}) {
logEntry.Errorf(format, args...)
}
// Fatalf logs a message at level Fatal on the standard logger
func Fatalf(format string, args ...interface{}) {
logEntry.Fatal(format, args)
}
// Panicf logs a message at level Panic on the standard logger
func Panicf(format string, args ...interface{}) {
logEntry.Panic(format, args)
}
// Debugln logs a message at level Debug on the standard logger.
func Debugln(args ...interface{}) {
logEntry.Debugln(args...)
}
// Infoln logs a message at level Info on the standard logger.
func Infoln(args ...interface{}) {
logEntry.Infoln(args...)
}
// Println logs a message at level Info on the standard logger.
func Println(args ...interface{}) {
logEntry.Println(args...)
}
// Warnln logs a message at level Warning on the standard logger.
func Warnln(args ...interface{}) {
logEntry.Warnln(args...)
}
// Warningln logs a message at level Warning on the standard logger.
func Warningln(args ...interface{}) {
logEntry.Warningln(args...)
}
// Errorln logs a message at level Error on the standard logger.
func Errorln(args ...interface{}) {
logEntry.Errorln(args...)
}
// Fatalln logs a message at level Fatal on the standard logger
func Fatalln(args ...interface{}) {
logEntry.Fatalln(args)
}
// Panicln logs a message at level Panic on the standard logger
func Panicln(args ...interface{}) {
logEntry.Panicln(args)
}