pino
pino copied to clipboard
`level` filter not work for transports
How to reproduce:
import pino from 'pino'
const transports = pino.transport({
targets: [{
level: 'error',
target: 'pino/file',
options: {
destination: '1' //stdout
}
}]
})
const logger = pino({}, transports)
logger.debug('Debug')
logger.info('Info')
logger.warn('Warn')
logger.error('Error')
Expected behavior:
node test
{"level":50,"time":1719528510555,"pid":47437,"hostname":"anime-desktop","msg":"Error"}
Actual behavior:
node test
{"level":30,"time":1719528510555,"pid":47437,"hostname":"anime-desktop","msg":"Info"}
{"level":40,"time":1719528510555,"pid":47437,"hostname":"anime-desktop","msg":"Warn"}
{"level":50,"time":1719528510555,"pid":47437,"hostname":"anime-desktop","msg":"Error"}
Same for any other transports
Version: 9.2.0 Node.js version: 18.20.3
Confirming this is new behavior since 9.0.0 and is not in line with the transports documentation. If I set level: 'error' on a target I should only get errors, if is set level: 'warn' I would get warn and errors. As it stands the level setting seems to be ignored atm.
I played around and determined this behavior change occurred with the 9.1.0 release. Figuring out the rest is beyond my skill.
Is this something that will be fixed? I can revert to 9.0.0 for now if there is no workaround, but that is only viable if the functionality will come back in a future release. If not...not sure what I am going to do TBH.
This is still an issue in 9.4. I am not sure the behavior is exactly the same, though. As of 9.4, when 2 targets are configured, levels work as expected; however, if only 1 is configured, the target level is ignored.
Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.
For me this is still not working in version 9.6.0. It looks like that 'level' for individual target in targets array is completely ignored and root 'level' from options is always used. If this is not defined it fallback to info.
Level property is the base for logging and not able to set different level for different target is quite problematic.
I have mostly tracked this issue down. As noted, this behaviour is different whenever you set up the parent level (as of 9.6.0). I have looked up through most of the multistream & transport code (seems fine) and noticed this is just the pino.debug call leading into a noop().
I'd assume most of the error lies in argument parsing and the default settings overriding, rather than logic, ie: the default level is set to 'info' regardless of the multistream options, which means the levelComparison in levels line 91 is setting pino.debug to noop().
Don't know what would be the easiest fix, probably looking up through the target in the normalize args function and override the level there. Would love someone giving their 2 cents on this.
I could work on a fix, would take me some time as I don't even have the environment setup properly, so in the meantime I thought I would share this info.