import pino from 'pino'
import { PinoPretty } from 'pino-pretty'
export const logger = pino({
level: process.env.PINO_LOG_LEVEL || 'info', // Not show events below the PINO_LOG_LEVEL variable or the default level 'info'
base: {
pid: false // Disables the pid field in the log output
},
transport: {
target: 'pino-pretty', // Uses the pino-pretty transport for pretty printing logs
options: {
colorize: true, // Enables colorized output
translateTime: 'SYS:yyyy-mm-dd HH:MM:ss' // Formats the time in a human-readable format
}
}
})
How to use:
import logger from './path/to/your/logger'
logger.fatal('fatal') // Critical errors causing application shutdown
logger.error('error') // Serious issues needing immediate attention
logger.warn('warn') // Potential problems or non-ideal situations
logger.info('info') // General operational information
logger.debug('debug') // Detailed debugging information for developers
logger.trace('trace') // Extremely detailed tracing of application execution
Output:
Notice: if the level is set to info, debug and trace will not be logged
Log an object with pino:
const user = {
username: 'John',
age: 20,
address: 'USA',
phone: '0123456789'
}
logger.info({ user }, 'Here is user info!')
cron job kill thread
[[NIKE BE LOG]]
Installing
Usage
Create
logger.ts
file in folderutils
In 'logger.ts':
How to use:
Output:
Notice: if the level is set to
info
, debug and trace will not be loggedLog an object with pino:
Output:
Can read these link for more information: https://betterstack.com/community/guides/logging/how-to-install-setup-and-use-pino-to-log-node-js-applications/
Documentation of Pino: https://getpino.io/#/