What is webpack-log?
The webpack-log package is a logging utility used in the webpack ecosystem. It provides a way to output logs with different levels of severity, such as 'info', 'warn', and 'error'. It is designed to work with webpack's node.js API and plugins to provide a consistent logging experience.
What are webpack-log's main functionalities?
Creating a logger instance
This code sample demonstrates how to create a new logger instance with a specified name. The logger can then be used to output informational messages.
const log = require('webpack-log');
const logger = log({ name: 'wds' });
logger.info('Server is starting...');
Logging warnings
This code sample shows how to log a warning message using the logger instance created earlier.
logger.warn('This is a warning message.');
Logging errors
This code sample illustrates how to log an error message, which could be used to output error information during the build process or plugin execution.
logger.error('An error has occurred!');
Other packages similar to webpack-log
signale
Signale is a console logger with a focus on providing beautiful output. It offers various log levels and custom loggers with configurable log messages. Compared to webpack-log, Signale is more versatile and can be used outside of the webpack context.
winston
Winston is a multi-transport async logging library for Node.js. It supports different storage options for log messages, such as files, databases, or third-party services. While webpack-log is specific to webpack, Winston is a more general-purpose logging solution with extensive features.
consola
Consola provides an easy-to-use and intuitive console logger. It is designed to work on both Node.js and browser environments and offers a variety of reporter options. Unlike webpack-log, Consola can be used for a wide range of applications, not limited to webpack.
webpack-log
A logger for the Webpack ecosystem.
Please consider donating if you find this project useful.
Requirements
This module requires an LTS Node version (v8.0.0+).
Install
Using npm:
npm install webpack-log --save-dev
Usage
Create a new logger and use it to log something wild:
const getLogger = require('webpack-log');
const log = getLogger({ name: 'webpack-batman' });
log.info('Jingle Bells, Batman Smells');
log.warn('Robin laid an egg');
log.error('The Batmobile lost a wheel');
log.debug('And the Joker got away');
And there will appear magic in your console:
Options
level
Type: String
Default: info
Specifies the level the logger should use. A logger will not produce output for
any log level beneath the specified level. Valid level names, and their order are:
[
'trace',
'debug',
'info',
'warn',
'error',
'silent'
]
For example, If a level was passed as { level: 'warn'}
then only calls to warn
and error
will be displayed in the terminal.
name
Type: String
Default: <webpack-log>
Specifies the name of the logger to create. This value will be part of the log output prefix.
timestamp
Type: Boolean
Default: false
If true
, the logger will display a timestamp for log output, preceding all other data
unique
Type: Boolean
Default: true
If false
, the logger will use cached versions of a log with the same name. Due to the nature of the webpack
ecosystem and multiple plugin/loader use in the same process, loggers are created as unique instances by default.
Meta
CONTRIBUTING
LICENSE (Mozilla Public License)