go-log/internal_logger_debug.go

63 lines
1001 B
Go
Raw Normal View History

2021-02-05 01:19:59 +00:00
package flog
import (
"fmt"
"io"
"strings"
)
2021-02-05 02:51:05 +00:00
func (receiver internalLogger) DebugMuted() bool {
return receiver.mutedDebug
2021-02-05 01:19:59 +00:00
}
func (receiver internalLogger) Debug(a ...interface{}) {
2021-02-05 02:51:05 +00:00
if receiver.DebugMuted() {
2021-02-05 01:19:59 +00:00
return
}
if nil == receiver.writer {
return
}
s := fmt.Sprint(a...)
receiver.Debugf("%s", s)
}
func (receiver internalLogger) Debugf(format string, a ...interface{}) {
2021-02-05 02:51:05 +00:00
if receiver.DebugMuted() {
2021-02-05 01:19:59 +00:00
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;2;44;181;233m")
case "":
buffer.WriteString("[debug] ")
}
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...)
}