2021-02-05 01:19:59 +00:00
|
|
|
package flog
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (receiver internalLogger) CanLogWarn() bool {
|
2021-02-05 02:25:22 +00:00
|
|
|
return !receiver.mutedWarn
|
2021-02-05 01:19:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (receiver internalLogger) Warn(a ...interface{}) {
|
|
|
|
if !receiver.CanLogWarn() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if nil == receiver.writer {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
s := fmt.Sprint(a...)
|
|
|
|
|
|
|
|
receiver.Warnf("%s", s)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (receiver internalLogger) Warnf(format string, a ...interface{}) {
|
|
|
|
if !receiver.CanLogWarn() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var writer io.Writer = receiver.writer
|
|
|
|
if nil == writer {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var newformat string
|
|
|
|
{
|
|
|
|
var buffer strings.Builder
|
|
|
|
|
|
|
|
switch receiver.style{
|
|
|
|
case"color":
|
|
|
|
buffer.WriteString("\x1b[48;2;1;1;1m")
|
|
|
|
buffer.WriteString("\x1b[38;222;56;43;6m")
|
|
|
|
case "":
|
|
|
|
buffer.WriteString("[warn] ")
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer.WriteString(format)
|
|
|
|
|
|
|
|
switch receiver.style {
|
|
|
|
case "color":
|
|
|
|
buffer.WriteString("\x1b[0m")
|
|
|
|
buffer.WriteRune('\n')
|
|
|
|
case "":
|
|
|
|
buffer.WriteRune('\n')
|
|
|
|
}
|
|
|
|
|
|
|
|
newformat = buffer.String()
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Fprintf(receiver.writer, newformat, a...)
|
|
|
|
}
|