-
Notifications
You must be signed in to change notification settings - Fork 1
/
error.go
executable file
·60 lines (54 loc) · 1.19 KB
/
error.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
package logger
import (
"github.com/Pantani/errors"
log "github.com/sirupsen/logrus"
)
type errMessage struct {
*message
err error
}
// Error log an error message
func Error(args ...interface{}) {
if len(args) == 0 {
Panic("call to logger.Error with no arguments")
}
e := getError(args...)
log.WithFields(e.params).Error(e.err)
}
// Fatal log a fatal message
func Fatal(args ...interface{}) {
if len(args) == 0 {
Panic("call to logger.Fatal with no arguments")
}
e := getError(args...)
log.WithFields(e.params).Fatal(e.err)
}
// Panic trigger a app panic with message
func Panic(args ...interface{}) {
if len(args) == 0 {
Panic("call to logger.Panic with no arguments")
}
e := getError(args...)
log.WithFields(e.params).Panic(e.err)
}
// getError parse arguments and creates the error message object
func getError(args ...interface{}) *errMessage {
msg := getMessage(args...)
err := &errMessage{message: msg}
for _, arg := range args {
switch arg := arg.(type) {
case *errors.Error:
err.err = arg
case error:
err.err = errors.E(arg)
case nil:
continue
default:
continue
}
}
if err.err == nil {
err.err = errors.E(msg.message, msg.params)
}
return err
}