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

Pino-pretty doesn't work if timestamp is changed #496

Open
augusto-dmh opened this issue Mar 12, 2024 · 2 comments
Open

Pino-pretty doesn't work if timestamp is changed #496

augusto-dmh opened this issue Mar 12, 2024 · 2 comments

Comments

@augusto-dmh
Copy link

I was trying to understand why, even with all due properties set and the script ok for running logs formatted with pino-pretty, why the logs were being this way - unformatted:

{"level":"ERROR"",timestamp":"2024-03-12T12:47:54.530Z","status":401,"message":"'authorization' header is required."

After checking if i was doing all the config stuff correctly, i tested taking off all configuration i've put on my logger, then i noticed that with timestamps changed like below, the prettier wouldn't work:

const logger = pino(
  {
    base: undefined,
    level: process.env.LOG_LEVEL,
    redact: {
      paths: ["email", "password"],
      censor: "[RESTRICTED]",
    },
    timestamp: () => `",timestamp":"${new Date(Date.now()).toISOString()}"`,
    formatters: {
      level: (label) => ({ level: label.toUpperCase() }),
    },
  },
  transport,
);

After removing the line with customized timestamp, the log was as should be:

[09:45:33.188] �[31mERROR�[39m:
status: 401
message: "'authorization' header is required."

So the pino-pretty package apparently doesnt work with a customized timestamp.

@mcollina
Copy link
Member

Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.

@augusto-dmh
Copy link
Author

You're welcome! Well, at the moment i haven't studied yet about unit tests, but sooner or later i will and i'll come back here!

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