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

Incorrect NotFound error logging #10272

Open
max-degterev opened this issue Dec 30, 2024 · 0 comments
Open

Incorrect NotFound error logging #10272

max-degterev opened this issue Dec 30, 2024 · 0 comments
Labels
status: needs-triage Possible bug which hasn't been reproduced yet

Comments

@max-degterev
Copy link

max-degterev commented Dec 30, 2024

Describe the Bug

Hi there, currently there are several issues with error logging:

  1. NotFound error is reported twice as a NotFound error and a generic Error
  2. NotFound erros are level error and not info
  3. It's not possible to override pino options without passing destination which removes formatting, so the only way to customize logging is just pass in a whole pino instance.

Link to the code that reproduces this issue

https://github.com/payloadcms/payload/blob/main/packages/payload/src/utilities/logger.ts#L38

AFAIK The only way to customize/suppress 404s and AuthErrors at the moment:

import { pino, type LoggerOptions } from 'pino';

const IGNORED_ERRORS = [
  /(Not\s?Found|not-found)/i,
  /AuthenticationError/i,
];

type MaybeError = {
  err?: {
    name?: string,
  },
};

const logMethod: NonNullable<LoggerOptions['hooks']>['logMethod'] = function(inputArgs, method) {
  const [error] = inputArgs;
  if (!error) return;

  const text = (error as MaybeError).err?.name || String(error);

  if (IGNORED_ERRORS.some((regex) => regex.test(text))) return;
  return method.apply(this, inputArgs);
};

const options: LoggerOptions = {
  hooks: {
    logMethod,
  },
  transport: {
    target: 'pino-pretty',
  },
};

const logger = pino(options);

export default logger;

Which area(s) are affected? (Select all that apply)

area: core

Environment Info

v3.12
@max-degterev max-degterev added status: needs-triage Possible bug which hasn't been reproduced yet validate-reproduction labels Dec 30, 2024
r1tsuu added a commit that referenced this issue Jan 2, 2025
Issue #10272

Adds `logError` utility that can be used across the codebase for logging
errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs-triage Possible bug which hasn't been reproduced yet
Projects
None yet
Development

No branches or pull requests

1 participant