Compare commits

...

1 Commits

Author SHA1 Message Date
Evan Chen 0f342edffa update 2021-11-11 15:01:29 +08:00
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
require kumoly.io/lib/klog v0.0.4
require kumoly.io/lib/klog v0.0.8
require (
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.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.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.SetPrinter(func(w io.Writer, d *klog.Ldata, l2 *klog.Logger) {
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 {
status = 500
}
@ -30,8 +38,7 @@ func New() *kserver {
StatusColor(status, l),
d.Fields["IP"],
MethodColor(d.Fields["Method"], l),
d.Fields["URL"], l.M(d.Message, klog.FgRed),
l.M(d.Stack, klog.FgRed),
d.Fields["URL"], msg, stack,
)
})