debug module using logfmt format
npm install debug-logfmt
- Based on the popular debug module.
- Lazy level evaluation used logs levels.
- Level support: info, warn & error based from RFC 5424.
- Message formatting Heroku logfmt syntax.
- Colorized output via DEBUG_COLORS by default.
- debug.duration for measurement.
``bash`
$ npm install debug-logfmt --save
Given a code like this one:
`js
const debug = require('debug-logfmt')('metascraper')
debug('retry', { url: 'https://kikobeats.com' })
debug.info('done', { time: Date.now() })
debug.warn('token expired', { timestamp: Date.now() })
debug.error('whoops', { message: 'expected number, got NaN' })`
You can:
- Allow all the levels: DEBUG=debug-logfmt*DEBUG=",-metascraper:info" node example.js
- Discard specific levels:
Sometimes you need to log the duration of a function:
`js
const { setTimeout } = require('timers/promises')
const debug = require('debug-logfmt')('metascraper')
const duration = debug.duration()
setTimeout(1001).then(() => duration.error('timeout!'))
setTimeout(1100).then(() => duration.info('success'))
`
#### env
Required
Type: string
The env variable name to use for enabling logging using DEBUG.
#### options
##### levels
Type: array['debug', 'info', 'warn', 'error']
Default:
The log levels available.
It returns a function will print the duration in the next call.
`js``
const duration = debug.duration('query')
const result = await db.query(query)
duration(result)
debug-logfmt © Kiko Beats, released under the MIT License.
Authored and maintained by Kiko Beats with help from contributors.
> kikobeats.com · GitHub Kiko Beats · X @Kikobeats