Closed nawapat-urnique closed 1 year ago
very similar thing happened with me. see #1638
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')
[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
{"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"}
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: @.***>
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.
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
The result at console and file is the same only info, warn, error, fatal is logged
But if I set level below info it works fine
result: