Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

transport for file does not work in middleware. #1909

Open
yaaasuu opened this issue Feb 26, 2024 · 2 comments
Open

transport for file does not work in middleware. #1909

yaaasuu opened this issue Feb 26, 2024 · 2 comments

Comments

@yaaasuu
Copy link

yaaasuu commented Feb 26, 2024

Hi, I try to export logs to the local file. But It does not work well.
When I set like the following and use "logger.info" in "/middleware.ts" , the log appear in the console only.
If I use "logger.info" in another place like "pages/api/auth/auth.ts" , the log appear in not only the console but also "./logs/app.log".

Do you have any way to export middleware logs?

const pinoConf = {
  level: "debug",
  transport: {
    targets: [
      {
        level: "info",
        target: "pino/file",
        options: { destination: "1" }, // stdout
      },
      {
        level: "info",
        target: "pino/file",
        options: {
          destination: "./logs/app.log",
          mkdir: true,
          sync: true,
        },
      },
    ],
  },
  timestamp: () =>
    `,"timestamp":"${new Date(Date.now()).toLocaleString("ja-JP", {
      timeZone: "Asia/Tokyo",
    })}"`,
  browser: {
    asObject: true,
  },
};
export const logger = pino(pinoConf);

@mcollina
Copy link
Member

middleware is like a browser environment (mostly because it has less capabilities than Node.js), therefore you are loading thr browser bundle instead.

I have no clue what the right bundling incantation you'd need to do to support this.

@yaaasuu
Copy link
Author

yaaasuu commented Feb 27, 2024

Thank you for replying.
I understand I have to another browser function instead of this library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants