-
I am using Remix with the official Express stack. I am using Pino logging for the application logging, this is all set up and working fine with JSON formatted output, eventually to be consumed by some cloud log service. What I am looking for now is any straightforward may to switch the Express request and error logging from the default console output to either a separate Pino log destination, or to have it merged with my application log messages - but in this case to have it also format the Express logs as JSON. Is anyone doing this? Is it even good practice to do this? This is similar to #2935, but that discussion is four years old, so I'm looking for any contemporary best practice here. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
To update request logging, just replace the call to And for error logging, you need to add a export function handleError(
error: unknown,
{
request,
params,
context,
}: LoaderFunctionArgs | ActionFunctionArgs
) {
if (!request.signal.aborted) {
// log to pino here
}
} https://remix.run/docs/en/main/file-conventions/entry.server#handleerror |
Beta Was this translation helpful? Give feedback.
In case anyone else needs the detail of what to do to make this work:
In the existing
server.ts
file that was generated by the Express template:Later in the same
server.ts
file:By default it will log everything, this is a slightly abridged example showing what you can expect to see when it's working: