forked from moredhel/env_logger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
errorhelpers.go
84 lines (74 loc) · 2.09 KB
/
errorhelpers.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
package env_logger
// Must Checks if an error occured, otherwise panic
func Must(err error) {
if err != nil {
getLogger(nil).Panicf("Error on must: %v", err)
}
}
// MustFatal Checks if an error occured, otherwise stop the program
func MustFatal(err error) {
if err != nil {
getLogger(nil).Fatalf("Fatal Error: %v", err)
}
}
// Should Checks if an error occured, otherwise prints it as error, returns true if error is not nil
func Should(err error) bool {
if err != nil {
getLogger(nil).Error(err)
return true
}
return false
}
// Should Checks if an error occured, otherwise prints it as error, returns true if error is not nil
func ShouldWrap(err error, msg string, args ...interface{}) bool {
if err != nil {
getLogger(nil).Error(Wrap(err, msg, args...))
return true
}
return false
}
// ShouldWarn Checks if an error occured, otherwise prints it as warning, returns true if error is not nil
func ShouldWarn(err error) bool {
if err != nil {
getLogger(nil).Warn(err)
return true
}
return false
}
// Must Checks if an error occured, otherwise panic
func (e *Entry) Must(err error) {
if err != nil {
getLogger(e).Panicf("Error on must: %v", err)
}
}
// MustFatal Checks if an error occured, otherwise stop the program
func (e *Entry) MustFatal(err error) {
if err != nil {
getLogger(e).Fatalf("Fatal Error: %v", err)
}
}
// ShouldWrap Checks if an error occured, otherwise prints it as error, returns true if error is not nil
func (e *Entry) ShouldWrap(err error, msg string, args ...interface{}) bool {
if err != nil {
getLogger(e).Error(Wrap(err, msg, args...))
return true
}
return false
}
// Should Checks if an error occured, otherwise prints it as error, returns true if error is not nil
func (e *Entry) Should(err error) bool {
if err != nil {
// Should get the linenumbers and goroutines!
getLogger(e).Error(err)
return true
}
return false
}
// ShouldWarn Checks if an error occured, otherwise prints it as warning, returns true if error is not nil
func (e *Entry) ShouldWarn(err error) bool {
if err != nil {
getLogger(e).Warn(err)
return true
}
return false
}