// LogFunc is a helper type to reduce typing.
type LogFunc func(level safcm.LogLevel, format string, a ...interface{})
-type Logger interface {
- Verbosef(format string, a ...interface{})
- Debugf(format string, a ...interface{})
- Debug2f(format string, a ...interface{})
-}
-
-type PrefixLogger struct {
+type Logger struct {
fun LogFunc
prefix string
}
-func NewLogger(prefix string, fun LogFunc) *PrefixLogger {
- return &PrefixLogger{
+func NewLogger(prefix string, fun LogFunc) *Logger {
+ return &Logger{
fun: fun,
prefix: prefix,
}
}
-func (l *PrefixLogger) Verbosef(format string, a ...interface{}) {
+func (l *Logger) Verbosef(format string, a ...interface{}) {
l.log(safcm.LogVerbose, format, a...)
}
-func (l *PrefixLogger) Debugf(format string, a ...interface{}) {
+func (l *Logger) Debugf(format string, a ...interface{}) {
l.log(safcm.LogDebug, format, a...)
}
-func (l *PrefixLogger) Debug2f(format string, a ...interface{}) {
+func (l *Logger) Debug2f(format string, a ...interface{}) {
l.log(safcm.LogDebug2, format, a...)
}
-func (l *PrefixLogger) log(level safcm.LogLevel,
+func (l *Logger) log(level safcm.LogLevel,
format string, a ...interface{}) {
l.fun(level, "%s %s", l.prefix, fmt.Sprintf(format, a...))
}