-
Notifications
You must be signed in to change notification settings - Fork 54
/
sessionlogger.go
69 lines (60 loc) · 1.4 KB
/
sessionlogger.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
package oonimkall
import (
"fmt"
"github.com/ooni/probe-cli/v3/internal/model"
)
type loggerVerbose struct {
Logger
}
func (slv loggerVerbose) Debugf(format string, v ...interface{}) {
slv.Debug(fmt.Sprintf(format, v...))
}
func (slv loggerVerbose) Infof(format string, v ...interface{}) {
slv.Info(fmt.Sprintf(format, v...))
}
func (slv loggerVerbose) Warnf(format string, v ...interface{}) {
slv.Warn(fmt.Sprintf(format, v...))
}
type loggerNormal struct {
Logger
}
func (sln loggerNormal) Debugf(format string, v ...interface{}) {
// nothing
}
func (sln loggerNormal) Debug(msg string) {
// nothing
}
func (sln loggerNormal) Infof(format string, v ...interface{}) {
sln.Info(fmt.Sprintf(format, v...))
}
func (sln loggerNormal) Warnf(format string, v ...interface{}) {
sln.Warn(fmt.Sprintf(format, v...))
}
type loggerQuiet struct{}
func (loggerQuiet) Debugf(format string, v ...interface{}) {
// nothing
}
func (loggerQuiet) Debug(msg string) {
// nothing
}
func (loggerQuiet) Infof(format string, v ...interface{}) {
// nothing
}
func (loggerQuiet) Info(msg string) {
// nothing
}
func (loggerQuiet) Warnf(format string, v ...interface{}) {
// nothing
}
func (loggerQuiet) Warn(msg string) {
// nothing
}
func newLogger(logger Logger, verbose bool) model.Logger {
if logger == nil {
return loggerQuiet{}
}
if verbose {
return loggerVerbose{Logger: logger}
}
return loggerNormal{Logger: logger}
}