refactor: move scrubbingLogger to the scrubber pkg (#394)
* refactor: move scrubbingLogger to the scrubber pkg We need it exported so we can use it in the new implementation. Part of https://github.com/ooni/probe/issues/1687 * fix test
This commit is contained in:
parent
75ae99e9d4
commit
1eb6e758c6
5 changed files with 181 additions and 145 deletions
62
internal/scrubber/logger.go
Normal file
62
internal/scrubber/logger.go
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
package scrubber
|
||||
|
||||
import "fmt"
|
||||
|
||||
// UnderlyingLogger defines the common interface that a logger should have. It is
|
||||
// out of the box compatible with `log.Log` in `apex/log`.
|
||||
type UnderlyingLogger interface {
|
||||
// Debug emits a debug message.
|
||||
Debug(msg string)
|
||||
|
||||
// Debugf formats and emits a debug message.
|
||||
Debugf(format string, v ...interface{})
|
||||
|
||||
// Info emits an informational message.
|
||||
Info(msg string)
|
||||
|
||||
// Infof formats and emits an informational message.
|
||||
Infof(format string, v ...interface{})
|
||||
|
||||
// Warn emits a warning message.
|
||||
Warn(msg string)
|
||||
|
||||
// Warnf formats and emits a warning message.
|
||||
Warnf(format string, v ...interface{})
|
||||
}
|
||||
|
||||
// Logger is a Logger with scrubbing. All messages are scrubbed
|
||||
// including the ones that won't be emitted. As such, this logger
|
||||
// is less efficient than a logger without scrubbing.
|
||||
type Logger struct {
|
||||
UnderlyingLogger
|
||||
}
|
||||
|
||||
// Debug scrubs and emits a debug message.
|
||||
func (sl *Logger) Debug(message string) {
|
||||
sl.UnderlyingLogger.Debug(Scrub(message))
|
||||
}
|
||||
|
||||
// Debugf scrubs, formats, and emits a debug message.
|
||||
func (sl *Logger) Debugf(format string, v ...interface{}) {
|
||||
sl.Debug(fmt.Sprintf(format, v...))
|
||||
}
|
||||
|
||||
// Info scrubs and emits an informational message.
|
||||
func (sl *Logger) Info(message string) {
|
||||
sl.UnderlyingLogger.Info(Scrub(message))
|
||||
}
|
||||
|
||||
// Infof scrubs, formats, and emits an informational message.
|
||||
func (sl *Logger) Infof(format string, v ...interface{}) {
|
||||
sl.Info(fmt.Sprintf(format, v...))
|
||||
}
|
||||
|
||||
// Warn scrubs and emits a warning message.
|
||||
func (sl *Logger) Warn(message string) {
|
||||
sl.UnderlyingLogger.Warn(Scrub(message))
|
||||
}
|
||||
|
||||
// Warnf scrubs, formats, and emits a warning message.
|
||||
func (sl *Logger) Warnf(format string, v ...interface{}) {
|
||||
sl.Warn(fmt.Sprintf(format, v...))
|
||||
}
|
||||
Loading…
Reference in a new issue