]> ruderich.org/simon Gitweb - safcm/safcm.git/blob - remote/log/logger.go
Use SPDX license identifiers
[safcm/safcm.git] / remote / log / logger.go
1 // Logging helpers
2
3 // SPDX-License-Identifier: GPL-3.0-or-later
4 // Copyright (C) 2021-2024  Simon Ruderich
5
6 package log
7
8 import (
9         "fmt"
10
11         "ruderich.org/simon/safcm"
12 )
13
14 // LogFunc is a helper type to reduce typing.
15 type LogFunc func(level safcm.LogLevel, msg string)
16
17 type Logger struct {
18         fun LogFunc
19 }
20
21 func NewLogger(fun LogFunc) *Logger {
22         return &Logger{
23                 fun: fun,
24         }
25 }
26
27 func (l *Logger) Verbosef(format string, a ...interface{}) {
28         l.log(safcm.LogVerbose, format, a...)
29 }
30 func (l *Logger) Debugf(format string, a ...interface{}) {
31         l.log(safcm.LogDebug, format, a...)
32 }
33 func (l *Logger) Debug2f(format string, a ...interface{}) {
34         l.log(safcm.LogDebug2, format, a...)
35 }
36
37 func (l *Logger) log(level safcm.LogLevel,
38         format string, a ...interface{}) {
39         l.fun(level, fmt.Sprintf(format, a...))
40 }