You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm still very new to go and might not be interpreting this correctly, but this is my current use case:
My small service:
is hosted in GCP
uses middleware.Logger only in debug mode = running locally since GCP already does the request logging automatically
uses the middleware.Recoverer (is last middleware, as per docs)
uses slog to manage all logging
Use case
While in debug mode, everything works as expected, outputs are sent to stdout/stderr and formatted properly.
But while in release mode, when panicking (which I understand should be rare since errors should be properly handled), the panic is caught by the middleware.Recoverer and printed to stderr directly (via PrintPrettyStack).
I wanted a way to get this output and put it into slog.
Why
The PrettyPrintStack outputs multiple lines to stderr, which causes the logger in GCP to interpret each line as an independent log entry.
Current solution
One alternative I tried was to just copy the parsing logic + middleware.Recover logic into a custom middleware.
Another way was to create a custom middleware that parses & adds LogEntry to context (an adapted version from middleware.Logger).
But I would still need to copy the PrintPrettyStack parsing functionality either way.
Is it possible to expose just the right functions or args to make it easier?
Or am I missing something (go or chi related) else entirely to make this work?
The text was updated successfully, but these errors were encountered:
williamhjcho
changed the title
Ability to set the default io.Writer when recovering
Custom middleware recovery having to be duplicated
Apr 23, 2024
Context
Hello 馃憢
I'm still very new to go and might not be interpreting this correctly, but this is my current use case:
My small service:
middleware.Logger
only in debug mode = running locally since GCP already does the request logging automaticallymiddleware.Recoverer
(is last middleware, as per docs)slog
to manage all loggingUse case
While in debug mode, everything works as expected, outputs are sent to stdout/stderr and formatted properly.
But while in release mode, when panicking (which I understand should be rare since errors should be properly handled), the panic is caught by the
middleware.Recoverer
and printed to stderr directly (viaPrintPrettyStack
).I wanted a way to get this output and put it into
slog
.Why
The
PrettyPrintStack
outputs multiple lines to stderr, which causes the logger in GCP to interpret each line as an independent log entry.Current solution
One alternative I tried was to just copy the parsing logic + middleware.Recover logic into a custom middleware.
Another way was to create a custom middleware that parses & adds LogEntry to context (an adapted version from
middleware.Logger
).But I would still need to copy the
PrintPrettyStack
parsing functionality either way.Is it possible to expose just the right functions or args to make it easier?
Or am I missing something (go or chi related) else entirely to make this work?
The text was updated successfully, but these errors were encountered: