Elegant Console Logger
- Easy to use
- Fancy output with fallback for minimal environments
- Pluggable reporters
- Consistent command line interface (CLI) experience
- Tag support
- Redirect
console
andstdout/stderr
to the consola and easily restore redirect. - Browser support
- Pause/Resume support
!!! Note: Consola v2 is stil under development. Meanwhile, you may want to use 1.x branch docs. !!!
Using yarn:
yarn add consola
Using npm:
npm i consola
const consola = require('consola')
// See types section for all available types
consola.success('Built!')
consola.info('Reporter: Some info')
consola.error(new Error('Foo'))
[15:21:29] [nuxt:router] [DEBUG ] consola log [15:21:29] [nuxt:router] [ERROR ] consola log [15:21:29] [nuxt:router] [FATAL ] consola log [15:21:29] [nuxt:router] [INFO ] consola log
Minimal Reporter (CI)
Log to all reporters.
Register a custom reporter instance.
Remove a registered reporter.
If no arguments are passed all reporters will be removed.
- Type:
Object
orArray
Replace all reporters.
Create a new Consola
instance and inherit all parent options for defaults.
Create a new Consola
instance with provided defaults
Create a new Consola
instance with that tag.
Globally redirect all console.log
, etc calls to consola handlers.
Globally redirect all stdout/stderr outputs to consola.
Wraps both std and console.
console uses std in the underlying so calling wrapStd
redirects console too.
Benefit of this function is that things like console.info
will be correctly redirected to the corresponding type.
Globally pause and resume logs.
Consola will enqueue all logs when paused and then sends them to the reported when resumed.
An array of active reporters.
The level to display logs. Any logs at or above this level will be displayed. List of available levels here.
You can set log level using CONSOLA_LEVEL
environment variable.
logObject is a free-to-extend object which will be passed to reporters.
Standard fields:
message
additional
args
date
tag
Choose between one of the built-in reporters or bring own reporter.
By default FancyReporter
is registered for modern terminals or BasicReporter
will be used if running in limited environments such as CIs.
Available reporters:
A reporter (Class or Object) exposes log(logObj)
method.
To write a reporter, check implementations to get an idea.
Types are logging levels. A list of all available default types is here.
Consola has a global instance and is recommended to use everywhere. In case more control is needed, create a new instance.
import consola from 'consola'
const logger = consola.create({
// level: 4,
reporters: [
new consola.JSONReporter()
],
defaults: {
additionalColor: 'white'
}
})
consola.setReporters({
log: jest.fn()
})
{
virtualConsole: new jsdom.VirtualConsole().sendTo(consola)
}
MIT - Made with 馃挅 By Nuxt.js team!