45 lines
946 B
Go
45 lines
946 B
Go
package gologger
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
const (
|
|
ErrorTemplate = "\033[1;31;40m%s\033[0m\n"
|
|
WarnTemplate = "\033[1;33;40m%s\033[0m\n"
|
|
InfoTemplate = "\033[1;32;40m%s\033[0m\n"
|
|
DebugTemplate = "\033[1;34;40m%s\033[0m\n"
|
|
TraceTemplate = "\033[1;35;40m%s\033[0m\n"
|
|
)
|
|
|
|
type ConsoleAppender struct{}
|
|
|
|
func (c *ConsoleAppender) GetName() string {
|
|
return "console"
|
|
}
|
|
|
|
func (c *ConsoleAppender) Append(logEvent LogEvent) {
|
|
data := []interface{}{
|
|
logEvent.Ts.Format("2006-01-02 15:04:05"),
|
|
" ",
|
|
}
|
|
dmsg := fmt.Sprint(logEvent.Data)
|
|
dmsg = strings.TrimLeft(dmsg, "[")
|
|
dmsg = strings.TrimRight(dmsg, "]")
|
|
data = append(data, dmsg)
|
|
logMsg := fmt.Sprint(data...)
|
|
switch logEvent.Level {
|
|
case Error:
|
|
fmt.Printf(ErrorTemplate, logMsg)
|
|
case Warn:
|
|
fmt.Printf(WarnTemplate, logMsg)
|
|
case Info:
|
|
fmt.Printf(InfoTemplate, logMsg)
|
|
case Debug:
|
|
fmt.Printf(DebugTemplate, logMsg)
|
|
case Trace:
|
|
fmt.Printf(TraceTemplate, logMsg)
|
|
}
|
|
}
|