pinojs / pino

🌲 super fast, all natural json logger
http://getpino.io
MIT License
14.21k stars 875 forks source link

The "level" property of "pino.transports" did not work as expected #1160

Closed pan93412 closed 3 years ago

pan93412 commented 3 years ago

Environment

{
  "dependencies": {
    "pino": "^7.0.1"
  }
}
$ node -v
v16.11.1

I'm in darwin/arm64.

Description

Consider this code:

const pino = require('pino');
const transport = pino.transport({
        level: "trace",
        target: 'pino/file',
});
const log = pino(transport);
log.error("Error!");
log.warn("Warn!");
log.info("Info!");
log.debug("Debug!");
log.trace("Trace!");

I expected it can print the log with the range from "error" to "trace"; however, it only prints the log with "error", "warn" and "info" level.

Expected Result

It would be worked like this code: ```js const pino = require('pino'); const log = pino({ level: "trace" }); log.error("Error!"); log.warn("Warn!"); log.info("Info!"); log.debug("Debug!"); log.trace("Trace!"); ```
{"level":50,"time":1634271718112,"pid":27365,"hostname":"pan93412-mbp.local","msg":"Error!"}
{"level":40,"time":1634271718113,"pid":27365,"hostname":"pan93412-mbp.local","msg":"Warn!"}
{"level":30,"time":1634271718113,"pid":27365,"hostname":"pan93412-mbp.local","msg":"Info!"}
{"level":20,"time":1634271718113,"pid":27365,"hostname":"pan93412-mbp.local","msg":"Debug!"}
{"level":10,"time":1634271718113,"pid":27365,"hostname":"pan93412-mbp.local","msg":"Trace!"}

Actual Result

{"level":50,"time":1634271603343,"pid":27301,"hostname":"pan93412-mbp.local","msg":"Error!"}
{"level":40,"time":1634271603343,"pid":27301,"hostname":"pan93412-mbp.local","msg":"Warn!"}
{"level":30,"time":1634271603343,"pid":27301,"hostname":"pan93412-mbp.local","msg":"Info!"}
(node:27301) Warning: File descriptor 1 closed but not opened in unmanaged mode
(Use `node --trace-warnings ...` to show where the warning was created)
climba03003 commented 3 years ago

pino default log level is info.

pino instance log level means the log allow to log. pino transport log level means the lowest level it can be received from instance.

If the instance log level is higher than transport log level, some of the log will be missing for transport.

This behavior is expected when using either transport or multistream. https://github.com/pinojs/pino/blob/master/docs/api.md#pinomultistreamoptions--stream

pan93412 commented 3 years ago

pino default log level is info.

pino instance log level means the log allow to log. pino transport log level means the lowest level it can be received from instance.

If the instance log level is higher than transport log level, some of the log will be missing for transport.

This behavior is expected when using either transport or multistream. https://github.com/pinojs/pino/blob/master/docs/api.md#pinomultistreamoptions--stream

So should I do this instead?

const pino = require('pino');
const transport = pino.transport({
        level: "trace",
        target: 'pino/file',
});
const log = pino({ level: "trace"}, transport);
log.error("Error!");
log.warn("Warn!");
log.info("Info!");
log.debug("Debug!");
log.trace("Trace!");

It seems working when passing {level: "trace"} to pino()

climba03003 commented 3 years ago

pino default log level is info. pino instance log level means the log allow to log. pino transport log level means the lowest level it can be received from instance. If the instance log level is higher than transport log level, some of the log will be missing for transport. This behavior is expected when using either transport or multistream. https://github.com/pinojs/pino/blob/master/docs/api.md#pinomultistreamoptions--stream

So should I do this instead?

const pino = require('pino');
const transport = pino.transport({
        level: "trace",
        target: 'pino/file',
});
const log = pino({ level: "trace"}, transport);
log.error("Error!");
log.warn("Warn!");
log.info("Info!");
log.debug("Debug!");
log.trace("Trace!");

It seems working when passing {level: "trace"} to pino()

Yes.

pan93412 commented 3 years ago

Thanks a lot!

github-actions[bot] commented 2 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.