2021-08-25 14:34:33 +01:00
|
|
|
package internal
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Logging interface {
|
|
|
|
Printf(format string, v ...interface{})
|
|
|
|
}
|
|
|
|
|
2024-04-15 11:01:20 +01:00
|
|
|
var defaultLogger = log.New(os.Stderr, "", log.LstdFlags)
|
|
|
|
|
|
|
|
var Logger Logging = &logger{
|
|
|
|
log: defaultLogger,
|
|
|
|
}
|
|
|
|
|
|
|
|
var Warn = &wrapper{
|
|
|
|
prefix: "WARN: bun: ",
|
|
|
|
logger: Logger,
|
|
|
|
}
|
|
|
|
|
|
|
|
var Deprecated = &wrapper{
|
|
|
|
prefix: "DEPRECATED: bun: ",
|
|
|
|
logger: Logger,
|
|
|
|
}
|
|
|
|
|
2021-08-25 14:34:33 +01:00
|
|
|
type logger struct {
|
|
|
|
log *log.Logger
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l *logger) Printf(format string, v ...interface{}) {
|
|
|
|
_ = l.log.Output(2, fmt.Sprintf(format, v...))
|
|
|
|
}
|
|
|
|
|
2024-04-15 11:01:20 +01:00
|
|
|
type wrapper struct {
|
|
|
|
prefix string
|
|
|
|
logger Logging
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *wrapper) Printf(format string, v ...interface{}) {
|
|
|
|
w.logger.Printf(w.prefix+format, v...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func SetLogger(newLogger Logging) {
|
|
|
|
if newLogger == nil {
|
|
|
|
Logger = &logger{log: defaultLogger}
|
|
|
|
} else {
|
|
|
|
Logger = newLogger
|
|
|
|
}
|
|
|
|
Warn.logger = Logger
|
|
|
|
Deprecated.logger = Logger
|
2021-08-25 14:34:33 +01:00
|
|
|
}
|