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) HighlightMuted() bool {
|
|
|
|
return receiver.mutedHighlight
|
2021-02-05 01:19:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (receiver internalLogger) Highlight(a ...interface{}) {
|
2021-02-05 02:51:05 +00:00
|
|
|
if receiver.HighlightMuted() {
|
2021-02-05 01:19:59 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if nil == receiver.writer {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
s := fmt.Sprint(a...)
|
|
|
|
|
|
|
|
receiver.Highlightf("%s", s)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (receiver internalLogger) Highlightf(format string, a ...interface{}) {
|
2021-02-05 02:51:05 +00:00
|
|
|
if receiver.HighlightMuted() {
|
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;153;0;17m")
|
|
|
|
buffer.WriteString("\x1b[38;2;252;246;245m")
|
|
|
|
case "":
|
|
|
|
buffer.WriteString("[HIGHLIGHT] ")
|
|
|
|
}
|
|
|
|
|
2021-02-05 03:54:35 +00:00
|
|
|
buffer.WriteString(receiver.prefix)
|
2021-02-05 01:19:59 +00:00
|
|
|
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...)
|
|
|
|
}
|