pino icon indicating copy to clipboard operation
pino copied to clipboard

Childlogger Loglevel not respected in the browser

Open KeKs0r opened this issue 3 years ago • 5 comments

Hi,

I am using pino in the browser, since I have some parts of my application that are used in the browser as well as on node.

When using pino in the browser, it seems that different log levels for Child loggers are not working: Here is my root logger

const logger = pino({
    level: 'info',ser: {
        asObject: false,
        serialize: false,

        transmit: {
            level: 'error',
            send: function (level, logEvent) {
             //... Send error to sentry
            },
        },
    },
})

const childLogger = logger.child({name:'child', level:'debug'})

logger.debug("Root Logger Debug") // not logged
logger.info("Root Info") // logged
childLogger.debug("Child Debug") // Not logged, but I think it should
childLogger.info("Child Info") // logged

The output looks like this image

It seems the level for the child logger, is just taken as additional property, instead of changing the level of the child logger.

KeKs0r avatar Feb 05 '21 11:02 KeKs0r

Would you like to send a Pull Request to address this issue? Remember to add unit tests.

mcollina avatar Feb 05 '21 12:02 mcollina

I had a similar issue which I solved in Chrome. Not sure if it's relevant.

image

jakobrosenberg avatar May 08 '21 17:05 jakobrosenberg

I have the same problem in the browser. Here a short reproducible setup: https://stackblitz.com/edit/typescript-5ka82t?devToolsHeight=33&file=index.ts

@mcollina As this feature will be quite handy in the upcoming future for us, I will look into it.

NicoVogel avatar Jun 02 '23 05:06 NicoVogel

The fix in #1725 only works partially. Setting the level via child.level = "debug" works, but providing it as an option in root.child() does not:

const root = pino({ level: "info" })
root.info("OK: root info WILL be logged.")
root.debug("OK: root debug will NOT be logged.")

const child1 = root.child({})
child1.level = "debug"
child1.info("OK: child1 info WILL be logged.")
child1.debug("OK: child1 debug WILL be logged.")

const child2 = root.child({}, { level: "debug" })
child2.info("OK: child2 info WILL be logged.")
child2.debug("ERROR: child2 debug will NOT be logged.") // <--

GeorgEchterling avatar Feb 28 '24 11:02 GeorgEchterling

@GeorgEchterling the code for the browser logger takes a while to get into. Don't know if I will manage to work on it in the near future to fix this issue.

NicoVogel avatar Feb 29 '24 14:02 NicoVogel