-
I'm attempting to use import { pino } from "pino";
console.log('Starting Logger...');
export default pino({
level: LOG_LEVEL,
transport: {
targets: [
{
level: LOG_LEVEL,
target: "pino/file",
options: {
destination: `${LOG_DIRECTORY}/my-app.log`,
append: true,
},
},
],
},
}); While this does work, I've noticed that I see Can someone help me understand what's going on here? Is module caching disabled in Remix? Is there a better way to handle logging? Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
In development, Remix App Server purges the require cache on every request. This is mainly to support You'll want to store your pino object on the import pino from "pino";
declare global {
var logger: pino.Logger;
}
const LOG_LEVEL = process.env.LOG_LEVEL || "info";
const LOG_DIRECTORY = process.env.LOG_DIRECTORY || "./logs";
function getLogger() {
console.log("Starting Logger...");
return pino({
level: LOG_LEVEL,
transport: {
targets: [
{
level: LOG_LEVEL,
target: "pino/file",
options: {
destination: `${LOG_DIRECTORY}/my-app.log`,
append: true,
},
},
],
},
});
}
const logger: pino.Logger =
process.env.NODE_ENV === "development"
? global.logger ?? (global.logger = getLogger())
: getLogger();
export default logger; |
Beta Was this translation helpful? Give feedback.
In development, Remix App Server purges the require cache on every request. This is mainly to support
<LiveReload/>
.You'll want to store your pino object on the
global
object to survive the purge.