/
log.go
52 lines (43 loc) · 1.19 KB
/
log.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
package cfgssh
import (
logg "log"
)
type (
// DebugLogger wrap *log.Loggers with this to display debug logging
DebugLogger *logg.Logger
// InfoLogger wrap *log.Loggers with this to display info logging
InfoLogger *logg.Logger
)
// log is a struct that provides debug and info logging. This name was intentionally chosen
// so that it conflicts the the std log package. And forces contributors to use this struct
// instead of the std logger.
type log struct{ debug, info *logg.Logger }
// OnErr checks to see if err is nil, if it is nil, then no error message is displayed. If
// it is not nil, then the message is displayed. It is a convenience method for the typical
// if err != nil conditional.
func (l log) OnErr(err error) log {
if err != nil {
return l
}
return log{} // they will be nil, so they won't log
}
func (l log) Debug(v ...interface{}) {
if l.debug != nil {
l.debug.Println(v...)
}
}
func (l log) Debugf(fmt string, v ...interface{}) {
if l.debug != nil {
l.debug.Printf(fmt, v...)
}
}
func (l log) Info(v ...interface{}) {
if l.info != nil {
l.info.Println(v...)
}
}
func (l log) Infof(fmt string, v ...interface{}) {
if l.info != nil {
l.info.Printf(fmt, v...)
}
}