Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a stacktrace-inducing template token #2442

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions middleware/logger.go
Expand Up @@ -3,6 +3,7 @@ package middleware
import (
"bytes"
"encoding/json"
"fmt"
"io"
"strconv"
"strings"
Expand Down Expand Up @@ -41,6 +42,7 @@ type (
// - user_agent
// - status
// - error
// - error_stacktrace (err passed through Sprintf's '%+v')
// - latency (In nanoseconds)
// - latency_human (Human readable)
// - bytes_in (Bytes received)
Expand Down Expand Up @@ -198,8 +200,12 @@ func LoggerWithConfig(config LoggerConfig) echo.MiddlewareFunc {
if err != nil {
// Error may contain invalid JSON e.g. `"`
b, _ := json.Marshal(err.Error())
b = b[1 : len(b)-1]
return buf.Write(b)
return buf.Write(b[1 : len(b)-1])
}
case "error_stacktrace":
if err != nil {
b, _ := json.Marshal(fmt.Sprintf("%+v", err))
return buf.Write(b[1 : len(b)-1])
}
case "latency":
l := stop.Sub(start)
Expand Down