feat: do not use fmt.Sprintf in http logger
This commit is contained in:
parent
be59be1795
commit
910f1f8ba2
|
@ -2,7 +2,6 @@ package chi
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -37,12 +36,19 @@ type LogEntry struct {
|
||||||
|
|
||||||
// Panic implements middleware.LogEntry
|
// Panic implements middleware.LogEntry
|
||||||
func (e *LogEntry) Panic(v interface{}, stack []byte) {
|
func (e *LogEntry) Panic(v interface{}, stack []byte) {
|
||||||
logger.Error(e.ctx, fmt.Sprintf("%s %s", e.method, e.path), logger.F("stack", string(stack)))
|
logger.Error(
|
||||||
|
e.ctx, "http panic",
|
||||||
|
logger.F("stack", string(stack)),
|
||||||
|
logger.F("host", e.host),
|
||||||
|
logger.F("method", e.method),
|
||||||
|
logger.F("path", e.path),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write implements middleware.LogEntry
|
// Write implements middleware.LogEntry
|
||||||
func (e *LogEntry) Write(status int, bytes int, header http.Header, elapsed time.Duration, extra interface{}) {
|
func (e *LogEntry) Write(status int, bytes int, header http.Header, elapsed time.Duration, extra interface{}) {
|
||||||
logger.Info(e.ctx, fmt.Sprintf("%s %s - %d", e.method, e.path, status),
|
logger.Info(
|
||||||
|
e.ctx, "http request",
|
||||||
logger.F("host", e.host),
|
logger.F("host", e.host),
|
||||||
logger.F("status", status),
|
logger.F("status", status),
|
||||||
logger.F("bytes", bytes),
|
logger.F("bytes", bytes),
|
||||||
|
|
Loading…
Reference in New Issue