From b2d5dd94dfb0cf2154f7c2da4b2e0bd292fed77e Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Wed, 12 May 2021 08:17:39 +0200 Subject: [PATCH] sync: simplify LogFunc to take the log message as string LogFunc is not directly called by regular code which makes the format string less useful. --- cmd/safcm-remote/log/logger.go | 4 ++-- cmd/safcm-remote/main.go | 4 ++-- cmd/safcm-remote/sync/sync_test.go | 5 ++--- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/cmd/safcm-remote/log/logger.go b/cmd/safcm-remote/log/logger.go index 8d88d89..8bf0a43 100644 --- a/cmd/safcm-remote/log/logger.go +++ b/cmd/safcm-remote/log/logger.go @@ -24,7 +24,7 @@ import ( ) // LogFunc is a helper type to reduce typing. -type LogFunc func(level safcm.LogLevel, format string, a ...interface{}) +type LogFunc func(level safcm.LogLevel, msg string) type Logger struct { fun LogFunc @@ -50,5 +50,5 @@ func (l *Logger) Debug2f(format string, a ...interface{}) { func (l *Logger) log(level safcm.LogLevel, format string, a ...interface{}) { - l.fun(level, "%s %s", l.prefix, fmt.Sprintf(format, a...)) + l.fun(level, l.prefix+" "+fmt.Sprintf(format, a...)) } diff --git a/cmd/safcm-remote/main.go b/cmd/safcm-remote/main.go index ab0bfae..a29f20c 100644 --- a/cmd/safcm-remote/main.go +++ b/cmd/safcm-remote/main.go @@ -73,11 +73,11 @@ func mainLoop() error { conn := safcm.NewGobConn(os.Stdin, os.Stdout) var logLevel safcm.LogLevel - logFunc := func(level safcm.LogLevel, format string, a ...interface{}) { + logFunc := func(level safcm.LogLevel, msg string) { if logLevel >= level { conn.Send(safcm.MsgLog{ Level: level, - Text: fmt.Sprintf(format, a...), + Text: msg, }) } } diff --git a/cmd/safcm-remote/sync/sync_test.go b/cmd/safcm-remote/sync/sync_test.go index 8ee1459..17ba044 100644 --- a/cmd/safcm-remote/sync/sync_test.go +++ b/cmd/safcm-remote/sync/sync_test.go @@ -124,9 +124,8 @@ func prepareSync(req safcm.MsgSyncReq, runner *testRunner) ( }() logger := log.NewLogger(logPrefix, - func(level safcm.LogLevel, format string, a ...interface{}) { - res.ch <- fmt.Sprintf("%d: %s", level, - fmt.Sprintf(format, a...)) + func(level safcm.LogLevel, msg string) { + res.ch <- fmt.Sprintf("%d: %s", level, msg) }) return &Sync{ req: req, -- 2.45.2