forked from semaphoreui/semaphore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrorLogging.go
41 lines (34 loc) · 1.04 KB
/
errorLogging.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
package util
import (
log "github.com/Sirupsen/logrus"
)
// LogWarning logs a warning with arbitrary field if error
func LogWarning(err error){
LogWarningWithFields(err, log.Fields{"level": "Warn"})
}
// LogWarningWithFields logs a warning with added field context if error
func LogWarningWithFields(err error, fields log.Fields){
if err != nil {
log.WithFields(fields).Warn(err.Error())
}
}
// LogError logs an error with arbitrary field if error
func LogError(err error) {
LogErrorWithFields(err, log.Fields{"level": "Error"})
}
// LogErrorWithFields logs a error with added field context if error
func LogErrorWithFields(err error, fields log.Fields) {
if err != nil {
log.WithFields(fields).Error(err.Error())
}
}
// LogPanic logs and panics with arbitrary field if error
func LogPanic(err error){
LogPanicWithFields(err, log.Fields{"level": "Panic"})
}
// LogPanicWithFields logs and panics with added field context if error
func LogPanicWithFields(err error, fields log.Fields){
if err != nil {
log.WithFields(fields).Panic(err.Error())
}
}