2022-07-19 20:31:25 +00:00
|
|
|
package logging
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
dbg *log.Logger
|
|
|
|
info *log.Logger
|
|
|
|
warn *log.Logger
|
|
|
|
err *log.Logger
|
|
|
|
)
|
|
|
|
|
|
|
|
func Init() {
|
|
|
|
flags := log.Ldate | log.Ltime | log.Lmicroseconds | log.Lshortfile | log.LUTC
|
|
|
|
dbg = log.New(os.Stdout, "DEBUG ", flags)
|
|
|
|
info = log.New(os.Stdout, "INFO ", flags)
|
|
|
|
warn = log.New(os.Stdout, "WARN ", flags)
|
|
|
|
err = log.New(os.Stdout, "ERROR ", flags)
|
|
|
|
}
|
|
|
|
|
|
|
|
func ErrorLogger() *log.Logger {
|
|
|
|
if err == nil {
|
|
|
|
return log.New(ioutil.Discard, "", log.LstdFlags)
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func Debugf(message string, args ...interface{}) {
|
|
|
|
if dbg == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if len(args) > 0 {
|
|
|
|
message = fmt.Sprintf(message, args...)
|
|
|
|
}
|
2022-07-29 20:31:54 +00:00
|
|
|
dbg.Output(2, message) //nolint:errcheck // we can't do anything with what we log
|
2022-07-19 20:31:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func Infof(message string, args ...interface{}) {
|
|
|
|
if info == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if len(args) > 0 {
|
|
|
|
message = fmt.Sprintf(message, args...)
|
|
|
|
}
|
2022-07-29 20:31:54 +00:00
|
|
|
info.Output(2, message) //nolint:errcheck // we can't do anything with what we log
|
2022-07-19 20:31:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func Warnf(message string, args ...interface{}) {
|
|
|
|
if warn == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if len(args) > 0 {
|
|
|
|
message = fmt.Sprintf(message, args...)
|
|
|
|
}
|
2022-07-29 20:31:54 +00:00
|
|
|
warn.Output(2, message) //nolint:errcheck // we can't do anything with what we log
|
2022-07-19 20:31:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func Errorf(message string, args ...interface{}) {
|
|
|
|
if err == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if len(args) > 0 {
|
|
|
|
message = fmt.Sprintf(message, args...)
|
|
|
|
}
|
2022-07-29 20:31:54 +00:00
|
|
|
err.Output(2, message) //nolint:errcheck // we can't do anything with what we log
|
2022-07-19 20:31:25 +00:00
|
|
|
}
|