npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

volog

v2.0.2

Published

Simple, light and beautiful logger

Downloads

39

Readme

VOLOG: Elevate Your Logs

"Empower Your Insights, Let Your Logs Soar with VOLOG"

VOLOG - where your application's logs don't just tell a story, they take flight, offering a higher perspective on your code's journey.

Installation

To start using VOLOG, install it in your project:

npm install volog

Importing and Using VOLOG

Import VOLOG into your JavaScript file:

import log from 'volog';

Basic Logging

VOLOG provides a straightforward way to log messages at different levels. The usage is similar for each level:

log.debug('Debug message');
log.info('Information message');
log.warn('Warning message');
log.error('Error message');
log.fatal('Fatal message');

Logging with Additional Context

To provide more context in your logs, VOLOG allows appending extra information. You can pass additional arguments after the message, and VOLOG will automatically format and display them:

log.info('User login', 'username', 'johndoe', 'attempt', 1);
log.warn('Memory usage high', 'threshold', '80%');
log.error('Database error', 'code', 500, 'retrying', false);

In this approach, each additional argument after the first (the message) is treated as part of the extras. VOLOG will group these extras and display them alongside the log message.

Customizing Logs with Settings

VOLOG allows customization of logging behavior through the volog.settings system. Here are the available settings along with their default values:

showTime (default: true): Display timestamp with each log message.

log.settings.showTime = true; // Enables timestamp in logs

scope: Define a scope or context for your log messages.

log.settings.scope = 'AuthenticationModule'; // Sets a specific scope

formatArguments (default: `true``): Toggle formatting for additional arguments.

log.settings.formatArguments = true; // Enables formatting for extras

argsFormatter: Provide a custom formatter for additional arguments. This function receives three parameters:

  • arg: The current argument from the log method call.
  • idx: The index (position) of the argument in the log method call.
  • chalk: A copy of the Chalk library, allowing you to apply text styles without needing to install Chalk separately.
log.settings.argsFormatter = (arg, idx, chalk) => chalk.green(`(${idx}): ${arg}`);

colorEntireRow (default: false): Color the entire log row instead of just the log level.

log.settings.colorEntireRow = true;

colorRowLevels (default: ['debug', 'info', 'warn', 'error', 'fatal']): Specify which log levels should have colored rows.

log.settings.colorRowLevels = ['error', 'fatal']; // Only 'error' and 'fatal' logs will have colored rows

customColorMap: Define custom colors for different log levels.

log.settings.customColorMap = {
  debug: 'blue',
  info: '\u001b[33m', // ANSI color code
  warn: (chalk) => chalk.bgYellow.black, // Using chalk function
  error: 91, // ANSI color number
  fatal: 'magenta'
};

Log Output

When a log function is called, VOLOG generates an output in the console which includes:

  • A timestamp (if enabled).
  • A scope (if defined).
  • A colored label indicating the log level (DEBUG, INFO, WARN, ERROR, FATAL).
  • The log message.
  • Any additional contextual information provided.

Scoped Settings

Settings in VOLOG are scoped to each import of the library. This means that you can have different settings for different areas of your code. For example, you might have different log settings for authentication and data processing modules.

If you want to maintain consistent settings across multiple files, it is recommended to create a wrapper for VOLOG. This wrapper can set up the desired settings and be imported wherever you need logging.

Example Usage with Scoped Settings

// logWrapper.js
import log from 'volog';

log.settings.showTime = true;
log.settings.scope = 'GlobalScope';
// Other settings...

export default log;

// In other files
import log from './logWrapper';

log.info('Server started', 'port', 3000);

Each of these log statements will produce a structured, color-coded output in the console, making it easier to track application behavior and troubleshoot issues effectively.

With VOLOG, logging becomes not just a way of recording what happens in your application, but also a tool for better understanding and debugging your application in real-time.