Name: consola
Owner: NUXT
Description: ? Elegant Console Logger
Created: 2018-03-31 15:47:47.0
Updated: 2018-04-03 00:02:48.0
Pushed: 2018-04-02 19:09:47.0
Homepage: null
Size: 177
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Elegant Console Logger
Using yarn:
add consola
Using npm:
i consola
t consola = require('consola')
ee types section for all available types
ola.start('Starting build')
ola.success('Built!')
ola.info('Reporter: Some info')
ola.error(new Error('Foo'))
Fancy Reporter
[2:17:17 PM] Starting build [2:17:17 PM] [TEST] Log from test scope [2:17:18 PM] Built! [2:17:18 PM] Some info [2:17:18 PM] Error: Foo
Minimal Reporter (CI)
Group logs using an scope:
t logger = consola.withScope('test')
er.info('Log from test scope') // [Test] Log from test scope
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:
Please see Examples for usage info.
A reporter (Class or Object) exposes log(logObj)
method.
To write a reporter, check implementations to get an idea.
Types can be treated as extended logging levels in Consola's world.
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.
t { Consola, BasicReporter } = require('consola')
t consola = new Consola({
level: 30,
reporters: [],
types: []
ola.add(BasicReporter)
consola.<type>([logObj|message|error])
Log to all reporters. If a plain string or error is given, then the message will be automatically translated to a logObject.
add(reporter)
Register a custom reporter instance.
remove(reporter)
Remove a registered reporter.
clear()
Remove all current reporters (Useful for writing tests).
withDefaults(defaults)
Create a wrapper interface with all types available and defaults
applied to all logs.
withScope(scope)
Shortcut to withDefaults({ scope })
.
level
The level to display logs. Any logs at or above this level will be displayed.
List of available levels here
logObject is a free-to-extend object which will be passed to reporters.
Here are standard possible fields:
Common fields:
message
date
scope
Extended fields:
clear
badge
additional
ola.clear().add({
g: jest.fn()
rtualConsole: new jsdom.VirtualConsole().sendTo(consola)
MIT