pinojs / pino

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

Cannot set log level for multiple transports #1639

Closed nawapat-urnique closed 1 year ago

nawapat-urnique commented 1 year ago

My pino version is 8.8.0 cannot set level above info when using multiple transport I copy code from API doc and change level to trace

const pino = require('pino')
const transport = pino.transport({
  targets: [{
    level: 'trace',
    target: 'pino-pretty' // must be installed separately
  }, {
    level: 'trace',
    target: 'pino/file',
    options: { destination: '/path/to/store/logs' }
  }]
})

const logger = pino(transport)
logger.trace('trace')
logger.debug('debug')
logger.info('info')
logger.warn('warn')
logger.error('error')
logger.fatal('fatal')

The result at console and file is the same only info, warn, error, fatal is logged

[18:38:25.878] INFO (7668): info
[18:38:25.879] WARN (7668): warn
[18:38:25.879] ERROR (7668): error
[18:38:25.879] FATAL (7668): fatal

But if I set level below info it works fine

const pino = require('pino')
const transport = pino.transport({
  targets: [{
    level: 'error',
    target: 'pino-pretty' // must be installed separately
  }, {
    level: 'error',
    target: 'pino/file',
    options: { destination: '/path/to/store/logs' }
  }]
})

const logger = pino(transport)
logger.trace('trace')
logger.debug('debug')
logger.info('info')
logger.warn('warn')
logger.error('error')
logger.fatal('fatal')

result:

[18:38:25.879] ERROR (7668): error
[18:38:25.879] FATAL (7668): fatal
ghost commented 1 year ago

very similar thing happened with me. see #1638

ademarsj commented 1 year ago

Pino works by default only loggin the level "info" and above, so if will wanna log lower levels will need to tell to Pino consider them first, and then you call you transports, i did that way and worked fine: (It will create in the root folder of your project the logs.txt file)

const pino = require('pino');
// const pretty = require('pino-pretty');
const path = require('path');

const destinationPath = path.join(__dirname, '/logs.txt');

const transport = pino.transport({
  targets: [
    {
      level: 'trace',
      target: 'pino/file',
      options: { destination: destinationPath }
    },
    {
      level: 'trace',
      target: 'pino-pretty' // must be installed separately
  }],
});

// const logger = pino(transport);
const logger = pino({
  level: 'trace',
}, transport);

logger.trace('trace')
logger.debug('debug')
logger.info('info')
logger.warn('warn')
logger.error('error')
logger.fatal('fatal')

Output:

Console:

[21:32:22.423] TRACE (25528): trace
[21:32:22.424] DEBUG (25528): debug
[21:32:22.424] INFO (25528): info
[21:32:22.424] WARN (25528): warn
[21:32:22.424] ERROR (25528): error
[21:32:22.424] FATAL (25528): fatal

logs.txt:

{"level":10,"time":1675643542423,"pid":25528,"hostname":"my-pc","msg":"trace"}
{"level":20,"time":1675643542424,"pid":25528,"hostname":"my-pc","msg":"debug"}
{"level":30,"time":1675643542424,"pid":25528,"hostname":"my-pc","msg":"info"}
{"level":40,"time":1675643542424,"pid":25528,"hostname":"my-pc","msg":"warn"}
{"level":50,"time":1675643542424,"pid":25528,"hostname":"my-pc","msg":"error"}
{"level":60,"time":1675643542424,"pid":25528,"hostname":"my-pc","msg":"fatal"}
ghost commented 1 year ago

Thank you!

On Sun, 5 Feb 2023 at 18:37, Ademar Seide @.***> wrote:

Pino works by default only loggin the level "info" and above, so if will wanna log lower levels will need to tell to Pino consider them first, and then you call you transports, i did that way and worked fine: (It will create in the root folder of your project the logs.txt file)

const pino = require('pino'); // const pretty = require('pino-pretty'); const path = require('path');

const destinationPath = path.join(__dirname, '/logs.txt');

const transport = pino.transport({ targets: [ { level: 'trace', target: 'pino/file', options: { destination: destinationPath } }, { level: 'trace', target: 'pino-pretty' // must be installed separately }], });

// const logger = pino(transport); const logger = pino({ level: 'trace', }, transport);

logger.trace('trace') logger.debug('debug')logger.info('info') logger.warn('warn') logger.error('error') logger.fatal('fatal')

Output: Console:

[21:32:22.423] TRACE (25528): trace [21:32:22.424] DEBUG (25528): debug [21:32:22.424] INFO (25528): info [21:32:22.424] WARN (25528): warn [21:32:22.424] ERROR (25528): error [21:32:22.424] FATAL (25528): fatal

logs.txt:

{"level":10,"time":1675643542423,"pid":25528,"hostname":"my-pc","msg":"trace"} {"level":20,"time":1675643542424,"pid":25528,"hostname":"my-pc","msg":"debug"} {"level":30,"time":1675643542424,"pid":25528,"hostname":"my-pc","msg":"info"} {"level":40,"time":1675643542424,"pid":25528,"hostname":"my-pc","msg":"warn"} {"level":50,"time":1675643542424,"pid":25528,"hostname":"my-pc","msg":"error"} {"level":60,"time":1675643542424,"pid":25528,"hostname":"my-pc","msg":"fatal"}

— Reply to this email directly, view it on GitHub https://github.com/pinojs/pino/issues/1639#issuecomment-1418324692, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANS5KCBX7YNCG33NUCBJIE3WWBBVVANCNFSM6AAAAAAUQFRFXY . You are receiving this because you commented.Message ID: @.***>

github-actions[bot] commented 1 year 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.