Skip to content

[Config] pinoWillSendConfig leads to configuration mutation #1963

Description

@nioc

Hello,

I just upgrade from pino 8.19.0 to 8.21.0 and my code encounter this error:

Error: Can not update runtime configuration property: "pinoWillSendConfig". Configuration objects are immutable unless ALLOW_CONFIG_MUTATIONS is set.
    at Object.set (/home/nicolas/Dev/brewery/node_modules/config/lib/config.js:421:19)
    at transport (/home/nicolas/Dev/brewery/node_modules/pino/lib/transport.js:114:30)
    at normalizeArgs (/home/nicolas/Dev/brewery/node_modules/pino/lib/tools.js:316:16)
    at pino (/home/nicolas/Dev/brewery/node_modules/pino/pino.js:90:28)
    at createPinoLogger (/home/nicolas/Dev/brewery/node_modules/fastify/lib/logger.js:42:14)
    at createLogger (/home/nicolas/Dev/brewery/node_modules/fastify/lib/logger.js:101:18)
    at fastify (/home/nicolas/Dev/brewery/node_modules/fastify/fastify.js:135:33)
    at exports.default (/home/nicolas/Dev/brewery/apps/server/src/api/index.ts:22:25)

Here is my code on src/api/index.ts:

import Fastify, { FastifyLoggerOptions } from 'fastify'
import { PinoLoggerOptions } from 'fastify/types/logger'
import config from 'config'
// ...

export default async () => {
  const server = Fastify({
    logger: config.get('api.logger') as PinoLoggerOptions | FastifyLoggerOptions,
  })
 // ...
}

And the config:

{
  "api": {
    "logger": {
      "level": "debug",
      "redact": {
        "paths": [
          "req.headers.authorization",
          "api.session.secret"
        ],
        "censor": "****"
      },
      "transport": {
        "target": "pino-pretty",
        "options": {
          "translateTime": "HH:MM:ss Z",
          "ignore": "pid,hostname"
        }
      }
    }
  }
}

I try to add a attribute in both logger and logger.transport.options, nothing changes... So the logger received this config object:

{
  "pinoWillSendConfig": true,
  "level": "debug",
  "redact": {
    "paths": [
      "req.headers.authorization",
      "api.session.secret"
    ],
    "censor": "****"
  },
  "transport": {
    "target": "pino-pretty",
    "options": {
      "pinoWillSendConfig": true,
      "translateTime": "HH:MM:ss Z",
      "ignore": "pid,hostname"
    }
  }
}

It seems it is #1930 which add this, can you help me?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions