Add simple debug logging.

This commit is contained in:
2020-12-23 16:28:57 +05:00
parent 935d5d8109
commit 95c8181d2a
10 changed files with 100 additions and 27 deletions

View File

@@ -0,0 +1,6 @@
package logger
// Config represents logging configuration.
type Config struct {
Debug bool `yaml:"debug"`
}

41
internal/logger/logger.go Normal file
View File

@@ -0,0 +1,41 @@
package logger
import "log"
// Logger responsible for all logging actions.
type Logger struct {
config *Config
}
// NewLogger creates new logging wrapper and returns it to caller.
func NewLogger(config *Config) *Logger {
l := &Logger{config: config}
return l
}
// Debugf is a wrapper around log.Printf which will work only when debug mode
// is enabled.
func (l *Logger) Debugf(template string, params ...interface{}) {
if l.config.Debug {
log.Printf(template, params...)
}
}
// Debugln is a wrapper around log.Println which will work only when debug mode
// is enabled.
func (l *Logger) Debugln(params ...interface{}) {
if l.config.Debug {
log.Println(params...)
}
}
// Infof is a wrapper around log.Printf.
func (l *Logger) Infof(template string, params ...interface{}) {
log.Printf(template, params...)
}
// Infoln is a wrapper around log.Println.
func (l *Logger) Infoln(params ...interface{}) {
log.Println(params...)
}