
Security News
NVD Concedes Inability to Keep Pace with Surging CVE Disclosures in 2025
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.
The consola npm package is a console logger for Node.js and browsers. It provides an easy-to-use API for logging information, warnings, errors, and more, with a focus on developer experience and universal compatibility.
Basic Logging
Consola allows you to log messages at various levels, such as info, warn, and error, which are color-coded and formatted for better readability.
const consola = require('consola');
consola.info('Information message');
consola.warn('Warning message');
consola.error('Error message');
Reporters
You can add custom reporters to modify how logs are displayed or processed, giving you control over the logging output.
const consola = require('consola');
consola.addReporter({
log(logObj) {
console.log(logObj.message);
}
});
Tagged Logging
Consola supports tagged logging, which allows you to prepend a tag to your log messages, making it easier to filter and identify logs related to specific parts of your application.
const consola = require('consola').withTag('my-tag');
consola.info('Tagged information message');
Log Level Control
You can control the log level threshold, which determines the minimum level of logs that will be displayed, allowing you to filter out less important logs in different environments.
const consola = require('consola');
consola.level = 3; // Only display logs with a level of 3 (errors) or higher
Winston is a multi-transport async logging library for Node.js. It is similar to consola in that it provides logging capabilities, but it also allows for more complex transport configurations, such as logging to files, databases, or remote services.
Pino is a very low overhead Node.js logger, which focuses on performance. It provides similar logging capabilities to consola but is designed to be as efficient as possible, making it suitable for high-performance applications.
Debug is a tiny Node.js debugging utility that is similar to consola's tagged logging feature. It allows you to create debug instances with different namespaces, which you can enable or disable using environment variables.
Log4js is a logging framework for Node.js, which provides similar functionality to consola. It supports multiple appenders, log levels, and layouts, and it can be configured via JSON configuration files.
Elegant Console Logger
Using yarn:
yarn add consola
Usin npm:
npm i consola
const consola = require('consola')
// See types section for all available types
consola.start('Starting build')
consola.success('Built!')
consola.info('Reporter: Some info')
consola.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)
You can group logs using an scope:
const logger = consola.withScope('test')
logger.info('Log from test scope') // [Test] Log from test scope
You can choose between one of the built-in reporters or bring your own.
By default FancyReporter
is registered for modern terminals or BasicReporer
will be used if running in limited environments such as CIs.
Available reporters:
Please see Examples for usage info.
A reporter is nothing more than a Class or Object that should expose log(logObj)
method.
See implementations to get idea how to write your own.
You can think of types like extended logging levels in Consola's world.
A list of all available default types is here.
Consola has a global instance and it is recommanded to use it everywehre. In case that you need more control, you can create a new instance too.
const { Consola, BasicReporter } = require('consola')
const consola = new Consola({
level: 30,
reporters: [],
types: []
})
consola.add(BasicReporter)
consola.<type>([logObj|message|error])
Log to all reporters. If a plain string or error is given it 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)
Creat a wrapper interface with all types available and defaults
applied to all logs.
withScope(scope)
Shortcut to withDefaults({ scope })
.
logObject is a free-to-extend object which will be passed into reporters.
Here are standard possible fields:
Common fields:
message
date
scope
Extended fields:
clear
badge
additional
consola.clear().add({
log: jest.fn()
})
{
virtualConsole: new jsdom.VirtualConsole().sendTo(consola)
}
MIT
FAQs
Elegant Console Wrapper
The npm package consola receives a total of 10,390,527 weekly downloads. As such, consola popularity was classified as popular.
We found that consola demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.
Security Fundamentals
Attackers use obfuscation to hide malware in open source packages. Learn how to spot these techniques across npm, PyPI, Maven, and more.
Security News
Join Socket for exclusive networking events, rooftop gatherings, and one-on-one meetings during BSidesSF and RSA 2025 in San Francisco.