2021-02-05 01:19:59 +00:00
|
|
|
package flog
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2021-02-05 02:51:05 +00:00
|
|
|
func (receiver internalLogger) FatalMuted() bool {
|
|
|
|
return receiver.mutedFatal
|
2021-02-05 01:19:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (receiver internalLogger) Fatal(a ...interface{}) {
|
|
|
|
s := fmt.Sprint(a...)
|
|
|
|
|
|
|
|
receiver.Fatalf("%s", s)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (receiver internalLogger) Fatalf(format string, a ...interface{}) {
|
2021-02-05 02:51:05 +00:00
|
|
|
if receiver.FatalMuted() {
|
2021-02-05 01:19:59 +00:00
|
|
|
os.Exit(1)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var writer io.Writer = receiver.writer
|
|
|
|
if nil == writer {
|
|
|
|
os.Exit(1)
|
|
|
|
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("[PANIC] ")
|
|
|
|
}
|
|
|
|
|
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...)
|
|
|
|
|
|
|
|
os.Exit(1)
|
|
|
|
}
|