go_goutils/logging/funcs_std.go

164 lines
2.0 KiB
Go
Raw Normal View History

2021-02-26 15:52:29 -05:00
package logging
2021-02-26 20:27:35 -05:00
import (
`fmt`
`log`
)
func (l *StdLogger) Setup() {
l.Logger = log.Default()
l.Logger.SetPrefix(l.Prefix)
}
func (l *StdLogger) Shutdown() {
// NOOP
_ = ""
}
2021-02-26 15:52:29 -05:00
func (l *StdLogger) doDebug(d bool) {
l.EnableDebug = d
}
func (l *StdLogger) setPrefix(prefix string) {
l.Prefix = prefix
2021-02-26 20:27:35 -05:00
l.Logger.SetPrefix(prefix)
2021-02-26 15:52:29 -05:00
}
func (l *StdLogger) Alert(s string, v ...interface{}) (err error) {
2021-02-26 20:27:35 -05:00
var msg string
if v != nil {
msg = fmt.Sprintf(s, v...)
} else {
msg = s
}
l.renderWrite(msg, "ALERT")
2021-02-26 15:52:29 -05:00
return
}
func (l *StdLogger) Crit(s string, v ...interface{}) (err error) {
2021-02-26 20:27:35 -05:00
var msg string
if v != nil {
msg = fmt.Sprintf(s, v...)
} else {
msg = s
}
l.renderWrite(msg, "CRITICAL")
2021-02-26 15:52:29 -05:00
return
}
func (l *StdLogger) Debug(s string, v ...interface{}) (err error) {
2021-02-26 20:27:35 -05:00
if !l.EnableDebug {
return
}
var msg string
if v != nil {
msg = fmt.Sprintf(s, v...)
} else {
msg = s
}
l.renderWrite(msg, "DEBUG")
2021-02-26 15:52:29 -05:00
return
}
func (l *StdLogger) Emerg(s string, v ...interface{}) (err error) {
2021-02-26 20:27:35 -05:00
var msg string
if v != nil {
msg = fmt.Sprintf(s, v...)
} else {
msg = s
}
l.renderWrite(msg, "EMERGENCY")
2021-02-26 15:52:29 -05:00
return
}
func (l *StdLogger) Err(s string, v ...interface{}) (err error) {
2021-02-26 20:27:35 -05:00
var msg string
if v != nil {
msg = fmt.Sprintf(s, v...)
} else {
msg = s
}
l.renderWrite(msg, "ERROR")
2021-02-26 15:52:29 -05:00
return
}
func (l *StdLogger) Info(s string, v ...interface{}) (err error) {
2021-02-26 20:27:35 -05:00
var msg string
if v != nil {
msg = fmt.Sprintf(s, v...)
} else {
msg = s
}
l.renderWrite(msg, "INFO")
2021-02-26 15:52:29 -05:00
return
}
func (l *StdLogger) Notice(s string, v ...interface{}) (err error) {
2021-02-26 20:27:35 -05:00
var msg string
if v != nil {
msg = fmt.Sprintf(s, v...)
} else {
msg = s
}
l.renderWrite(msg, "NOTICE")
2021-02-26 15:52:29 -05:00
return
}
func (l *StdLogger) Warning(s string, v ...interface{}) (err error) {
2021-02-26 20:27:35 -05:00
var msg string
if v != nil {
msg = fmt.Sprintf(s, v...)
} else {
msg = s
}
l.renderWrite(msg, "WARNING")
return
}
func (l *StdLogger) renderWrite(msg, prio string) {
s := fmt.Sprintf("[%v] %v", prio, msg)
l.Logger.Println(s)
2021-02-26 15:52:29 -05:00
return
}