镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Formatter is very fragile #44

Open

Description

@ramblingenzyme

https://github.com/pinojs/pino/blob/master/docs/api.md#messagekey-string

Configuring messageKey will cause the formatter to fail.

Additionally we configure a formatter for level which returns status, to meet Datadog's expectations https://docs.datadoghq.com/logs/log_configuration/attributes_naming_convention/#reserved-attributes.

    level: (label: string) => ({
      status: label,
    }),
  },

Activity

  1. added
    bugSomething isn't working
    documentationImprovements or additions to documentation
    on Nov 6, 2023
  2. carbonrobot commented on Nov 7, 2023

    @carbonrobot
    Contributor

    pino runs the custom destination as the last function in the call chain, so the level and messagekey are not known to pino-lambda by the time pino calls our formatter. The fix is pretty simple, however, by supplying your own custom formatter.

    import { LogData, ILogFormatter } from 'pino-lambda';
    
    class CustomLogFormatter implements ILogFormatter {
      format(data: LogData): string {
        const { 
          awsRequestId,
          // your custom message key
          customMessageKey,
          // your custom level label key
          status
        } = data;
    
        // extract parts for message format
        const time = new Date().toISOString();
    
        return `${time}${
          awsRequestId ? `\t${awsRequestId}` : ''
        }\t${status.toUpperCase()}\t${msg}\t${JSON.stringify(data)}`;
      }
    }
    
    const destination = pinoLambdaDestination({
      formatter: new CustomLogFormatter(),
    });
    const logger = pino(destination);
  3. alexander-williamson commented on Dec 19, 2025

    @alexander-williamson

    We also ran into something similar - we would like to use the library but have our messageKey go from msg to message

    PS thanks for this library, it's really useful !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions