master
Evan Chen 2021-11-11 14:46:59 +08:00
parent f2579ec65a
commit 0f342edffa
3 changed files with 12 additions and 3 deletions

2
go.mod
View File

@ -2,7 +2,7 @@ module kumoly.io/lib/ksrv
go 1.17 go 1.17
require kumoly.io/lib/klog v0.0.4 require kumoly.io/lib/klog v0.0.8
require ( require (
github.com/mattn/go-isatty v0.0.14 // indirect github.com/mattn/go-isatty v0.0.14 // indirect

2
go.sum
View File

@ -12,3 +12,5 @@ kumoly.io/lib/klog v0.0.3 h1:DpJ6i9Y5I4DCEBb7j5oaAPc9tUTB9rDHE2J4bqmsYJY=
kumoly.io/lib/klog v0.0.3/go.mod h1:Snm+c1xRrh/RbXsxQf7UGYbAJGPcIa6bEEN+CmzJh7M= kumoly.io/lib/klog v0.0.3/go.mod h1:Snm+c1xRrh/RbXsxQf7UGYbAJGPcIa6bEEN+CmzJh7M=
kumoly.io/lib/klog v0.0.4 h1:Ev9G/zvLt/C8Q1yWfYoUcXVJWgPMjpqHPat2WKyOPIM= kumoly.io/lib/klog v0.0.4 h1:Ev9G/zvLt/C8Q1yWfYoUcXVJWgPMjpqHPat2WKyOPIM=
kumoly.io/lib/klog v0.0.4/go.mod h1:Snm+c1xRrh/RbXsxQf7UGYbAJGPcIa6bEEN+CmzJh7M= kumoly.io/lib/klog v0.0.4/go.mod h1:Snm+c1xRrh/RbXsxQf7UGYbAJGPcIa6bEEN+CmzJh7M=
kumoly.io/lib/klog v0.0.8 h1:6hTfDlZh7KGnPrd2tUrauCKRImSnyyN9DHXpey3Czn8=
kumoly.io/lib/klog v0.0.8/go.mod h1:Snm+c1xRrh/RbXsxQf7UGYbAJGPcIa6bEEN+CmzJh7M=

View File

@ -21,6 +21,14 @@ 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) status, ok := d.Fields["Status"].(int)
msg := d.Message
if msg != "" {
msg = l.M(msg, klog.FgRed)
}
stack := d.Stack
if stack != "" {
stack = l.M(stack, klog.FgRed)
}
if !ok { if !ok {
status = 500 status = 500
} }
@ -30,8 +38,7 @@ func New() *kserver {
StatusColor(status, 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"], msg, stack,
l.M(d.Stack, klog.FgRed),
) )
}) })