From b833e6d877e00290146fcd1e75a533664cf2dcb7 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Wed, 12 May 2021 08:14:26 +0200 Subject: [PATCH] sync: replace log.Logger interface with struct PrefixLogger is the only implementation of Logger. Simply remove the interface and rename PrefixLogger to Logger. --- cmd/safcm-remote/info/info.go | 2 +- cmd/safcm-remote/log/logger.go | 20 +++++++------------- cmd/safcm-remote/run/cmd.go | 4 ++-- cmd/safcm-remote/sync/sync.go | 2 +- 4 files changed, 11 insertions(+), 17 deletions(-) diff --git a/cmd/safcm-remote/info/info.go b/cmd/safcm-remote/info/info.go index c3853dd..4de44f3 100644 --- a/cmd/safcm-remote/info/info.go +++ b/cmd/safcm-remote/info/info.go @@ -31,7 +31,7 @@ type Info struct { resp safcm.MsgInfoResp cmd *run.Cmd - logger *log.PrefixLogger + logger *log.Logger } const logPrefix = "info remote:" diff --git a/cmd/safcm-remote/log/logger.go b/cmd/safcm-remote/log/logger.go index 159e097..8d88d89 100644 --- a/cmd/safcm-remote/log/logger.go +++ b/cmd/safcm-remote/log/logger.go @@ -26,35 +26,29 @@ import ( // 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...)) } diff --git a/cmd/safcm-remote/run/cmd.go b/cmd/safcm-remote/run/cmd.go index 4700ea3..36e4e75 100644 --- a/cmd/safcm-remote/run/cmd.go +++ b/cmd/safcm-remote/run/cmd.go @@ -28,10 +28,10 @@ import ( type Cmd struct { Runner Runner - logger log.Logger + logger *log.Logger } -func NewCmd(runner Runner, logger log.Logger) *Cmd { +func NewCmd(runner Runner, logger *log.Logger) *Cmd { return &Cmd{ Runner: runner, logger: logger, diff --git a/cmd/safcm-remote/sync/sync.go b/cmd/safcm-remote/sync/sync.go index 6f1cb78..706791f 100644 --- a/cmd/safcm-remote/sync/sync.go +++ b/cmd/safcm-remote/sync/sync.go @@ -37,7 +37,7 @@ type Sync struct { triggersActive map[string]bool cmd *run.Cmd - log *log.PrefixLogger + log *log.Logger } const logPrefix = "sync remote:" -- 2.45.2