forked from slayercat/GoSNMPServer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.go
133 lines (102 loc) · 3.57 KB
/
logger.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
package GoSNMPServer
import "os"
import "github.com/sirupsen/logrus"
// ILogger is a logger
type ILogger interface {
Debug(args ...interface{})
Debugf(format string, args ...interface{})
Debugln(args ...interface{})
Error(args ...interface{})
Errorf(format string, args ...interface{})
Errorln(args ...interface{})
Fatal(args ...interface{})
Fatalf(format string, args ...interface{})
Fatalln(args ...interface{})
Info(args ...interface{})
Infof(format string, args ...interface{})
Infoln(args ...interface{})
Trace(args ...interface{})
Tracef(format string, args ...interface{})
Traceln(args ...interface{})
Warn(args ...interface{})
Warnf(format string, args ...interface{})
Warning(args ...interface{})
Warningf(format string, args ...interface{})
Warningln(args ...interface{})
Warnln(args ...interface{})
}
//DefaultLogger is a logger warps logrus
type DefaultLogger struct {
*logrus.Logger
}
//NewDefaultLogger makes a new DefaultLogger
func NewDefaultLogger() ILogger {
var log = logrus.New()
log.Out = os.Stdout
log.Level = logrus.TraceLevel
return WrapLogrus(log)
}
//WrapLogrus wraps a new DefaultLogger
func WrapLogrus(p *logrus.Logger) ILogger {
return &DefaultLogger{p}
}
//DiscardLogger throws away everything
type DiscardLogger struct{}
//Debug throws away logmessage
func (*DiscardLogger) Debug(args ...interface{}) {}
//Debugf throws away logmessage
func (*DiscardLogger) Debugf(format string, args ...interface{}) {}
//Debugln throws away logmessage
func (*DiscardLogger) Debugln(args ...interface{}) {}
//Error throws away logmessage
func (*DiscardLogger) Error(args ...interface{}) {}
//Errorf throws away logmessage
func (*DiscardLogger) Errorf(format string, args ...interface{}) {}
//Errorln throws away logmessage
func (*DiscardLogger) Errorln(args ...interface{}) {}
//Fatal throws away logmessage
func (*DiscardLogger) Fatal(args ...interface{}) {}
//Fatalf throws away logmessage
func (*DiscardLogger) Fatalf(format string, args ...interface{}) {}
//Fatalln throws away logmessage
func (*DiscardLogger) Fatalln(args ...interface{}) {}
//Info throws away logmessage
func (*DiscardLogger) Info(args ...interface{}) {}
//Infof throws away logmessage
func (*DiscardLogger) Infof(format string, args ...interface{}) {}
//Infoln throws away logmessage
func (*DiscardLogger) Infoln(args ...interface{}) {}
//Trace throws away logmessage
func (*DiscardLogger) Trace(args ...interface{}) {}
//Tracef throws away logmessage
func (*DiscardLogger) Tracef(format string, args ...interface{}) {}
//Traceln throws away logmessage
func (*DiscardLogger) Traceln(args ...interface{}) {}
//Warn throws away logmessage
func (*DiscardLogger) Warn(args ...interface{}) {}
//Warnf throws away logmessage
func (*DiscardLogger) Warnf(format string, args ...interface{}) {}
//Warning throws away logmessage
func (*DiscardLogger) Warning(args ...interface{}) {}
//Warningf throws away logmessage
func (*DiscardLogger) Warningf(format string, args ...interface{}) {}
//Warningln throws away logmessage
func (*DiscardLogger) Warningln(args ...interface{}) {}
//Warnln throws away logmessage
func (*DiscardLogger) Warnln(args ...interface{}) {}
//NewDiscardLogger makes a discard logger
func NewDiscardLogger() ILogger {
return new(DiscardLogger)
}
// SnmpLoggerAdapter adapts a logger to gosnmp. wraps logger as trace
type SnmpLoggerAdapter struct {
ILogger
}
//Print wraps trace
func (i *SnmpLoggerAdapter) Print(args ...interface{}) {
i.ILogger.Trace(args...)
}
//Printf wraps trace
func (i *SnmpLoggerAdapter) Printf(format string, args ...interface{}) {
i.ILogger.Tracef(format, args...)
}