nuxt/consola

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

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Consola

Elegant Console Logger

Why Consola?
Installation

Using yarn:

 add consola

Using npm:

i consola
Getting started
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)


Scoped Loggers

Group logs using an scope:

t logger = consola.withScope('test')

er.info('Log from test scope') // [Test] Log from test scope
Reporters

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.

Creating your own reporter

A reporter (Class or Object) exposes log(logObj) method. To write a reporter, check implementations to get an idea.

Types

Types can be treated as extended logging levels in Consola's world.

A list of all available default types is here.

Creating a new instance

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)
API

Log to all reporters. If a plain string or error is given, then the message will be automatically translated to a logObject.

Register a custom reporter instance.

Remove a registered reporter.

Remove all current reporters (Useful for writing tests).

Create a wrapper interface with all types available and defaults applied to all logs.

Shortcut to withDefaults({ scope }).

The level to display logs. Any logs at or above this level will be displayed.
List of available levels here

logObject

logObject is a free-to-extend object which will be passed to reporters.

Here are standard possible fields:

Common fields:

Extended fields:

Integrations
With jest
ola.clear().add({
g: jest.fn()

With jsdom

rtualConsole: new jsdom.VirtualConsole().sendTo(consola)

License

MIT


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.