Skip to content
Discussion options

You must be logged in to vote

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.

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,
          }

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@atomdmac
Comment options

@kiliman
Comment options

Answer selected by atomdmac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants