Skip to content

Tricky BigInt values displayed incorrectly #633

@dnechay

Description

@dnechay

Hey 👋🏻
Thank you for this amazing tool!

We use pino and pino-pretty in everyday dev env and constantly work with logging different BigInt values. Recently found out that by some reason pino-pretty distorts the value that is passed to pino.info and correctly serialized by it.

Env:

  • Node.js version: v22.14.0
  • pino version: 9.7.0
  • pino-pretty version: 13.0.0

Sample script:

import pino from 'pino';

const MESSAGE_KEY = 'message';

const logger = pino({
  name: 'PlaygorundLogger',
  base: null,
  messageKey: MESSAGE_KEY,
  timestamp: () => `,"timestamp":${Date.now()}`,
  formatters: {
    level: (label) => ({ level: label })
  },
  // transport: {
  //   target: 'pino-pretty',
  //   options: {
  //     messageKey: MESSAGE_KEY,
  //     // translateTime: "UTC:yyyy-mm-dd'T'HH:MM:ss'Z'",
  //     translateTime: "SYS:yyyy-mm-dd, HH:MM:ss'Z'",
  //   },
  // },
});

const wierdBigintStr = '1666666666666666700';
const weirdBigint = BigInt(wierdBigintStr);

(async () => {
  try {
    logger.info({
      weirdBigint,
      wierdBigintStr,
      asString: weirdBigint.toString(),
      asValueOf: weirdBigint.valueOf(),
    }, 'weirdBigint');
    process.exit(0);
  } catch (error) {
    logger.error('Failed', error);
    process.exit(1);
  }
})();

Result w/o pino-pretty transport:

{
  "level": "info",
  "timestamp": 1762865459988,
  "weirdBigint": 1666666666666666700,
  "wierdBigintStr": "1666666666666666700",
  "asString": "1666666666666666700",
  "asValueOf": 1666666666666666700,
  "message": "weirdBigint"
}

Result w/ pino-pretty transport:

[2025-11-11, 15:55:42Z] INFO: weirdBigint
    weirdBigint: 1666666666666666800
    wierdBigintStr: "1666666666666666700"
    asString: "1666666666666666700"
    asValueOf: 1666666666666666800

As you can see it prints a value with 8 instead of 7, but not sure why.

Hope you can help with it 🙏🏻

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions