go-watchdog/log.go

39 lines
875 B
Go
Raw Normal View History

2020-12-02 16:33:00 +00:00
package watchdog
import "log"
// logger is an interface to be implemented by custom loggers.
type logger interface {
2020-12-02 16:33:00 +00:00
Debugf(template string, args ...interface{})
Infof(template string, args ...interface{})
Warnf(template string, args ...interface{})
Errorf(template string, args ...interface{})
}
var _ logger = (*stdlog)(nil)
2020-12-02 16:33:00 +00:00
// stdlog is a logger that proxies to a standard log.logger.
2020-12-02 16:33:00 +00:00
type stdlog struct {
log *log.Logger
debug bool
}
func (s *stdlog) Debugf(template string, args ...interface{}) {
if !s.debug {
return
}
s.log.Printf(template, args...)
}
func (s *stdlog) Infof(template string, args ...interface{}) {
s.log.Printf(template, args...)
}
func (s *stdlog) Warnf(template string, args ...interface{}) {
s.log.Printf(template, args...)
}
func (s *stdlog) Errorf(template string, args ...interface{}) {
s.log.Printf(template, args...)
}