master
Evan Chen 2021-11-11 14:46:16 +08:00
parent 52501e0d01
commit f2579ec65a
1 changed files with 5 additions and 1 deletions

View File

@ -20,10 +20,14 @@ func (k *kserver) GetLogger() *klog.Logger {
func New() *kserver { func New() *kserver {
l := klog.Sub("KSRV") l := klog.Sub("KSRV")
l.SetPrinter(func(w io.Writer, d *klog.Ldata, l2 *klog.Logger) { l.SetPrinter(func(w io.Writer, d *klog.Ldata, l2 *klog.Logger) {
status, ok := d.Fields["Status"].(int)
if !ok {
status = 500
}
fmt.Fprintf(w, "[%s] %s |%s| %15s %s %s %s\n%s", fmt.Fprintf(w, "[%s] %s |%s| %15s %s %s %s\n%s",
l.M("KSRV ", klog.FgHiCyan), l.M("KSRV ", klog.FgHiCyan),
d.Time.Format("2006/01/02 15:04:05"), d.Time.Format("2006/01/02 15:04:05"),
StatusColor(d.Fields["Status"].(int), l), StatusColor(status, l),
d.Fields["IP"], d.Fields["IP"],
MethodColor(d.Fields["Method"], l), MethodColor(d.Fields["Method"], l),
d.Fields["URL"], l.M(d.Message, klog.FgRed), d.Fields["URL"], l.M(d.Message, klog.FgRed),