go-log/internal_logger_highlight.go

63 lines
1.0 KiB
Go
Raw Normal View History

2021-02-05 01:19:59 +00:00
package flog
import (
"fmt"
"io"
"strings"
)
func (receiver internalLogger) CanLogHighlight() bool {
return !receiver.canNotLogHighlight
}
func (receiver internalLogger) Highlight(a ...interface{}) {
if !receiver.CanLogHighlight() {
return
}
if nil == receiver.writer {
return
}
s := fmt.Sprint(a...)
receiver.Highlightf("%s", s)
}
func (receiver internalLogger) Highlightf(format string, a ...interface{}) {
if !receiver.CanLogHighlight() {
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] ")
}
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...)
}