Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
loglevel-colored-level-prefix
Advanced tools
loglevel plugin that adds colored level prefix (node only)
The loglevel-colored-level-prefix package is an extension for the loglevel logging library that adds colored level prefixes to log messages. This helps in distinguishing log levels visually, making it easier to read and debug logs.
Colored Level Prefixes
This feature adds colored prefixes to log messages based on their level (info, warn, error, etc.). The colors help in quickly identifying the severity of the messages.
const log = require('loglevel');
const prefix = require('loglevel-colored-level-prefix');
prefix.apply(log);
log.info('This is an info message');
log.warn('This is a warning message');
log.error('This is an error message');
Custom Prefix Format
This feature allows you to customize the format of the log message prefixes. You can define a template that includes the log level, timestamp, and message.
const log = require('loglevel');
const prefix = require('loglevel-colored-level-prefix');
prefix.apply(log, {
template: '[%l] %t: %m',
level: 'info'
});
log.info('This is an info message');
log.warn('This is a warning message');
log.error('This is an error message');
Custom Colors
This feature allows you to customize the colors used for different log levels. You can use any color supported by the chalk library.
const log = require('loglevel');
const prefix = require('loglevel-colored-level-prefix');
prefix.apply(log, {
level: 'info',
format: {
info: chalk.blue,
warn: chalk.yellow,
error: chalk.red
}
});
log.info('This is an info message');
log.warn('This is a warning message');
log.error('This is an error message');
Winston is a versatile logging library for Node.js that supports multiple transports (e.g., console, file, HTTP) and log levels. It also supports custom formatting and coloring of log messages. Compared to loglevel-colored-level-prefix, Winston offers more advanced features and flexibility but may be more complex to set up.
Bunyan is another logging library for Node.js that provides a simple and fast JSON-based logging system. It supports log levels, custom serializers, and streams. Bunyan's focus on JSON output makes it different from loglevel-colored-level-prefix, which focuses on colored text output.
Pino is a fast and low-overhead logging library for Node.js. It supports log levels, custom serializers, and transports. Pino is designed for high performance and low overhead, making it suitable for production environments. Unlike loglevel-colored-level-prefix, Pino does not focus on colored output but on performance.
loglevel plugin that adds colored level prefix (node only)
loglevel
is great, and I find that I often want the log output to
be formatted the same way every time. Also I don't really like some of the
implementation of loglevel
(specifically the fact that it uses some browser
APIs for some things.
This exposes a function to get a logger (singleton) with colored prefixes for
the level. Note that this only works in Node because it uses chalk
.
This module is distributed via npm which is bundled with node and should
be installed as one of your project's dependencies
:
npm install --save loglevel-colored-level-prefix
const getLogger = require('loglevel-colored-level-prefix')
const options = {prefix: 'your-prefix', level: 'trace'}
const logger = getLogger(options)
logger.trace('WOW! What the stack trace!?')
// Trace: your-prefix [TRACE]: WOW! What the stack trace!?
// at Logger.trace (<full-path>/node_modules/loglevel-colored-level-prefix/dist/index.js:54:24)
// at ... etc
logger.debug('sup debug?')
// your-prefix [DEBUG]: sup debug?
logger.info('Hey info')
// your-prefix [INFO]: Hey info
logger.warn('Hi warn')
// your-prefix [WARN]: Hi warn
logger.error('Hello error')
// your-prefix [ERROR]: Hello error
Let's look at what that actually looks like...
?String - Whatever you want your prefix to be. Normally this is the tool
that you're logging for. The getLogger
function will return the same instance
of the logger based on the given prefix.
?String - What you want the initial level to be set to. This defaults to:
process.env.LOG_LEVEL || 'warn'
. Possible options are (in order of verbosity):
trace
, debug
, info
, warn
, error
.
An instance of a loglevel
logger. Learn more about that API from the
loglevel
docs.
I wrote this because I wanted to use the plugin I created for
prettier-eslint
in
prettier-eslint-cli
. And I'll probably use it in other
projects/tools as well.
I'm unaware of other plugins for loglevel
that do what this one does. But
there are many logging solutions out there...
Thanks goes to these people (emoji key):
Kent C. Dodds 💻 📖 🚇 ⚠️ |
---|
This project follows the all-contributors specification. Contributions of any kind welcome!
MIT
FAQs
loglevel plugin that adds colored level prefix (node only)
The npm package loglevel-colored-level-prefix receives a total of 685,008 weekly downloads. As such, loglevel-colored-level-prefix popularity was classified as popular.
We found that loglevel-colored-level-prefix demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.