Simple configurable logging module.
This package is part of quark
framework but it can be used independently.
- Levels : Defaults (
log
,info
,warn
,error
) and custom - Plugins : Defaults and custom
- Styling : Per level/plugin
- More : Timer, group, reset...
npm install quark-log --save
import { Logger } from 'quark-log'
const logger = new Logger()
logger.log('Test')
logger.log('Test', { test: true })
logger.log('Test', 10, true)
import { Logger } from 'quark-log'
const logger = new Logger()
logger.off()
logger.log('This test will not be logged')
logger.on()
import { Logger } from 'quark-log'
const logger = new Logger()
logger.group('Group')
logger.log('Test grouping')
logger.groupEnd()
import { Logger } from 'quark-log'
const logger = new Logger()
logger.time('timer')
// ...
logger.timeEnd('timer')
import { Logger } from 'quark-log'
const logger = new Logger()
logger.setHandler(msgs => {
// msgs = ['Test', true]
})
logger.log('Test', true)
Reset levels and plugins.
import { Logger, plugins } from 'quark-log'
const logger = new Logger()
logger.plugin('time', plugins.time)
logger.log('Test') // [15:00:00] Test
logger.reset()
logger.log('Test') // Test
import { Logger } from 'quark-log'
const logger = new Logger()
logger.br()
import { Logger } from 'quark-log'
const logger = new Logger()
logger.log('Log')
logger.info('Info')
logger.warn('Warn')
logger.error('Error')
import { Logger } from 'quark-log'
const logger = new Logger()
logger.level('custom')
logger.custom('My custom level')
import { Logger } from 'quark-log'
const logger = new Logger()
logger.level('custom', {
styles: {
color: 'blue'
}
})
logger.custom('Test') // Will be logged in blue
- time : Append current time before user message
- namespace : Append a custom namespace before user message
import { Logger, plugins } from 'quark-log'
const logger = new Logger()
logger.plugin('time', plugins.time)
logger.log('Test') // [15:00:00] Test
import { Logger, plugins } from 'quark-log'
const logger = new Logger()
logger.plugin('namespace', plugins.namespace, { name: 'test' })
logger.log('Test') // [test] Test
logger.plugin('namespace', { enabled: false })
logger.log('Test') // Test
import { Logger } from 'quark-log'
/**
* Plugin callback signature
*
* @param {Array} msgs User messages
* @param {Object} options Plugin options
* @param {Object} level Level
* @param {String} level.name Level name
* @param {Object} level.options Level options
*/
const myPlugin = (msgs, options, level) => {
return { before: `${options.myOption}:`, msgs, after: '', styles: {} }
}
const logger = new Logger()
logger.plugin('myPlugin', myPlugin, { myOption: 'My plugin' }) // This plugin append a custom string before each message
logger.log('Test') // My plugin: Test
See https://fm-ph.github.io/quark-log/
To build the sources with babel
in ./lib
directory :
npm run build
To generate the JSDoc
:
npm run docs
To generate the documentation and deploy on gh-pages
branch :
npm run docs:deploy
To serve the JSDoc
:
npm run docs:serve
To run the tests, first clone the repository and install its dependencies :
git clone https://github.com/fm_ph/quark-log.git
cd quark-log
npm install
Then, run the tests :
npm test
To watch (test-driven development) :
npm run test:watch
For coverage :
npm run test:coverage
MIT License Β© Patrick Heng Fabien Motte