]> ruderich.org/simon Gitweb - safcm/safcm.git/commitdiff
sync: simplify LogFunc to take the log message as string
authorSimon Ruderich <simon@ruderich.org>
Wed, 12 May 2021 06:17:39 +0000 (08:17 +0200)
committerSimon Ruderich <simon@ruderich.org>
Wed, 12 May 2021 06:25:36 +0000 (08:25 +0200)
LogFunc is not directly called by regular code which makes the format
string less useful.

cmd/safcm-remote/log/logger.go
cmd/safcm-remote/main.go
cmd/safcm-remote/sync/sync_test.go

index 8d88d8948b4e332ae72638058fa67b87ee2d4a3a..8bf0a43ee0506b94a5edb02fe42dbd473910ce21 100644 (file)
@@ -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...))
 }
index ab0bfae917286283e59bcb16af1c2ffabe15432a..a29f20c171747ac6f3a72935c33a1ca6e162dd8a 100644 (file)
@@ -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,
                        })
                }
        }
index 8ee14593148dc5b48eb95bc4f7e9ba31dd44eabc..17ba044b2e5e75d44530809d055ab9a600054d4c 100644 (file)
@@ -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,