Mugetsu
Mugetsu9mo ago

LoggerLink logging only via server logger in prod

I have a logger link setup as declared in https://trpc.io/docs/client/links/loggerLink#usage
loggerLink({
enabled: (op) =>
process.env.NODE_ENV === 'development' ||
(op.direction === 'down' && op.result instanceof Error),
}),
loggerLink({
enabled: (op) =>
process.env.NODE_ENV === 'development' ||
(op.direction === 'down' && op.result instanceof Error),
}),
This is logging to console.log by default as I understand correctly. I have a specific logger instance using pino which can be used only on the server side. How do I acommodate this loggerlink to log errors via my logger instance only if it ERRORS in PRODUCTION?
Logger Link | tRPC
loggerLink is a link that lets you implement a logger for your tRPC client. It allows you to see more clearly what operations are queries, mutations, or subscriptions, their requests, and responses. The link, by default, prints a prettified log to the browser's console. However, you can customize the logging behavior and the way it prints to the...
1 Reply
Mugetsu
Mugetsu9mo ago
Is it fine like this??
loggerLink({
logger: (op) => {
if (op.direction === 'down' && op.result instanceof Error) {
trpcLogger.error(op.result);
trpcLogger.error(
op.result.cause?.cause,
'Aggregated trpc error cause',
);
}
},
enabled: (op) =>
process.env.NODE_ENV === 'development' ||
(op.direction === 'down' && op.result instanceof Error),
}),
loggerLink({
logger: (op) => {
if (op.direction === 'down' && op.result instanceof Error) {
trpcLogger.error(op.result);
trpcLogger.error(
op.result.cause?.cause,
'Aggregated trpc error cause',
);
}
},
enabled: (op) =>
process.env.NODE_ENV === 'development' ||
(op.direction === 'down' && op.result instanceof Error),
}),