@relab/winston-logger
v1.0.11
Published
Winston logger configuration
Downloads
3
Readme
@relab/node-logger
Winston-based logger configuration with Telegram integration.
Usage
npm install --save @relab/node-logger
- Configure layout, verbosity level and Telegram (if necessary)
- Patch
console
object:
import { patchCommonLogger } from '@relab/node-logger'
patchCommonLogger()
- Import
logger
to write logs into default area - Import
scoped
to create log area
Configuration
Layout
import { configureLogger } from '@relab/node-logger'
configureLogger({ kind: 'layout', layout: ['timestamp', 'level', 'area', 'message', 'details', 'error'] })
Verbosity level
import { configureLogger } from '@relab/node-logger'
configureLogger({ kind: 'verbosity', verbosity: { area: '*', level: 'error' } })
configureLogger({ kind: 'verbosity', verbosity: { area: 'express', level: 'debug' } })
Telegram
import { configureLogger } from '@relab/node-logger'
configureLogger({
kind: 'telegram',
telegram: {
enabled: true,
token: process.env.LOGGER_TELEGRAM_TOKEN ?? '',
chatId: Number(process.env.LOGGER_TELEGRAM_CHAT_ID),
}
})
Example of usage
import { patchCommonLogger, logger, scoped, configureLogger } from '@relab/node-logger'
// Configure and patch logger
configureLogger({ kind: 'layout', layout: ['timestamp', 'level', 'area', 'message', 'details', 'error'] })
configureLogger({ kind: 'verbosity', verbosity: { area: '*', level: 'error' } })
configureLogger({ kind: 'verbosity', verbosity: { area: 'express', level: 'debug' } })
configureLogger({
kind: 'telegram',
telegram: {
enabled: true,
token: process.env.LOGGER_TELEGRAM_TOKEN ?? '',
chatId: Number(process.env.LOGGER_TELEGRAM_CHAT_ID),
}
})
patchCommonLogger()
// Create scoped logger
const expressLogger = scoped('express')
// Use logger
logger.info('Starting application')
expressLogger.info('Starting web-server')
expressLogger.error('Unable to start web-server')
console.log('Default message') // also works
License
Released under MIT by Sergey Zwezdin.