GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Pino object logger option gets cloned after #568 · Issue #574 · fastify/fastify-cli

Pino object logger option gets cloned after #568 #574

New issue
Copy link
New issue
Copy link
Open
Open
Pino object logger option gets cloned after #568#574
Copy link
Labels
bugConfirmed bughelp wantedHelp the community by contributing to this issue

Description

@stefanosala
stefanosala
opened on Dec 13, 2022
Issue body actions

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

4.10.2

Plugin version

5.7.0

Node.js version

18.12.1

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

13.0.1

Description

After #568 was merged, the new behavior of deepmerge clone the options object and tries to clone any instance of Pino we pass as option, modifying it into a simple object so that all the Pino settings are lost.

Steps to Reproduce

Given the following fastify startup module:

import pino from 'pino';

export default async function (fastify, options) {
  fastify.get('/', async (req, reply) => ({ hello: 'world' }));
}

const logger = pino({
  transport: {
    target: 'pino-pretty',
  },
});

export const options = {
  logger,
};

When using fastify-cli like this:

node_modules/.bin/fastify start --options a.js

I get this output:

{"level":30,"time":1670931640310,"pid":68940,"hostname":"Stefanos-MacBook-Air.local","msg":"Server listening at http://[::1]:3000"}
{"level":30,"time":1670931640311,"pid":68940,"hostname":"Stefanos-MacBook-Air.local","msg":"Server listening at http://127.0.0.1:3000"}

Expected Behavior

The expected output would be something like this instead:

[12:41:03.421] INFO (69034): Server listening at http://[::1]:3000
[12:41:03.422] INFO (69034): Server listening at http://127.0.0.1:3000

I would tend to think that deepmerge should be modified in order to clone by reference any type of object that is not a plain JS object, but I'd appreciate any feedback in order to try and provide a patch for this.

Reacted by Segev Finer

Activity

  1. Eomm commented on Dec 13, 2022

    @Eomm
    Eomm
    on Dec 13, 2022
    Member
    More actions

    Thanks for reporting

    Let me check what I broke

  2. jordanebelanger commented on Jan 19, 2023

    @jordanebelanger
    jordanebelanger
    on Jan 19, 2023
    More actions

    Thanks for reporting

    Let me check what I broke

    Would be great if this can get some attention, this was really hard to debug and a huge head scratcher while I tried to figure out why my logger was no longer working as expected in production.

  3. Tom-Brouwer commented on Feb 22, 2023

    @Tom-Brouwer
    Tom-Brouwer
    on Feb 22, 2023
    More actions

    Thanks for reporting

    Let me check what I broke

    Great, thanks for your response.

    Like @jordanebelanger I have a custom logger defined in my options in app.js, and no logs were being generated anymore after an update of fastify-cli.

    As mentioned by the TS, the issue is in version 5.6.1 and above. On 5.6.0 it is still working. The workaround for now is to stick to 5.6.0.

    Please let me know if there's any more information you need.

  4. stefanosala commented on May 4, 2023

    @stefanosala
    stefanosala
    on May 4, 2023
    Author
    More actions

    @Eomm I've gone a bit into the rabbit hole and I can't seem to find an elegant solution to this issue.

    deepmerge will try to clone the EventEmitter from Pino because we try to merge a logger option on this line and that seems to be "by design", so I'm not really sure how to help here, I'm sorry!

  5. Eomm commented on May 5, 2023

    @Eomm
    Eomm
    on May 5, 2023
    Member
    More actions

    I think we should explore a bit the cloneProtoObject parameter: https://github.com/fastify/fastify-cli/pull/568/files#diff-a32491fa91f5482043b89399c88b89b58e660137d926f75dab64e9c56cf454a0R9

    If we check the obj prototype, we should be able to understand if we must clone it or not

  6. stefanosala commented on May 5, 2023

    @stefanosala
    stefanosala
    on May 5, 2023
    Author
    More actions

    Thanks, what type of objects do you think we should clone?
    My guess would be to clone only plain objects (Object.getPrototypeOf(value) === Object.prototype)?

  7. stefanosala commented on May 5, 2023

    @stefanosala
    stefanosala
    on May 5, 2023
    Author
    More actions

    Actually, that callback isn't being called in this case because it goes on this line, where it is directly being merged into target.

    In my example above, target is a plain object and source is an EventEmitter.

  8. segevfiner commented on Sep 9, 2024

    @segevfiner
    segevfiner
    on Sep 9, 2024
    Contributor
    More actions

    Offff. So I'm stuck with [email protected] for the time being...

  9. segevfiner commented on Sep 9, 2024

    @segevfiner
    segevfiner
    on Sep 9, 2024
    Contributor
    More actions

    I used the logging-module as a workaround which is also annoying as I need to craft a separate file and compile it specially to share state with the main bundle and it also doesn't support ESM (#760)

    I think the problem might be that _deepmerge in @fastify/deepmerge isn't checking for cloneProtoObject and the prototype before entering mergeObject, which then will recurse using _deepmerge into the logger property so it never actually reaches cloneObject or cloneProtoObject

  10. vdp641 commented on Oct 24, 2024

    @vdp641
    vdp641
    on Oct 24, 2024
    More actions

    Hi, any update on it? I've tried versions 5.9, 6, and 7 of the fastifly-cli, but I'm still encountering the following error:

    FastifyError [Error]: Invalid logger object provided. The logger instance should have these functions(s): 'child'.

  11. mcollina commented on Oct 25, 2024

    @mcollina
    mcollina
    on Oct 25, 2024
    Member
    More actions

    I guess the easiest way is for a volunteer to send a PR to fix.

  12. mcollina
    added
    bugConfirmed bug
    help wantedHelp the community by contributing to this issue
    on Oct 25, 2024
  13. kilisamemarisaaa commented on Aug 28, 2026

    @kilisamemarisaaa
    kilisamemarisaaa
    on Aug 28, 2026 · Hidden as spam
    show commentMore actions
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

    bugConfirmed bughelp wantedHelp the community by contributing to this issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.