2020-12-23 16:28:57 +05:00
|
|
|
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 {
|
2021-06-04 13:50:12 +05:00
|
|
|
if config == nil {
|
|
|
|
config = &Config{Debug: false}
|
|
|
|
}
|
|
|
|
|
2020-12-23 16:28:57 +05:00
|
|
|
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...)
|
|
|
|
}
|