// Logging helpers // Copyright (C) 2021-2024 Simon Ruderich // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . package log import ( "fmt" "ruderich.org/simon/safcm" ) // LogFunc is a helper type to reduce typing. type LogFunc func(level safcm.LogLevel, msg string) type Logger struct { fun LogFunc } func NewLogger(fun LogFunc) *Logger { return &Logger{ fun: fun, } } func (l *Logger) Verbosef(format string, a ...interface{}) { l.log(safcm.LogVerbose, format, a...) } func (l *Logger) Debugf(format string, a ...interface{}) { l.log(safcm.LogDebug, format, a...) } func (l *Logger) Debug2f(format string, a ...interface{}) { l.log(safcm.LogDebug2, format, a...) } func (l *Logger) log(level safcm.LogLevel, format string, a ...interface{}) { l.fun(level, fmt.Sprintf(format, a...)) }