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

vorpal-log

v1.1.0

Published

Logging/Printing utility for vorpal.

Downloads

40

Readme

Vorpal - Log

Build Status

A Vorpal.js extension adding simple logging methods.

Installation

npm install vorpal-log
npm install vorpal

Getting Started

const vorpal = (require('vorpal'))();
const vorpalLog = require('vorpal-log');

vorpal.use(vorpalLog)
  .delimiter('vorpal-log demo $')
  .show();

const logger = vorpal.logger;

vorpal.command('log')
  .action(function(args, cb) {
  logger.debug('Log command called without arguments.');
  logger.log('Foo, bar, baz!');
  logger.confirm('You successfully ran the log command.');
  logger.info('It logs stuff.');
  logger.warn('Careful with that axe, Eugene!');
  logger.error('Something went wrong...');
  logger.fatal('If this was a real program, it would probably shut down now.');
  cb();
});

logger.info('This is a demo program for the vorpal-log extension.');
logger.info('Run log to produce some output.');
logger.info('Run loglevel <level> to change the level, e.g. \'loglevel warn\'');

Default Functionality

Vorpal-log comes with the following predefined methods for logging:

  • logger.debug(msg) (loglevel 10)
  • logger.log(msg) (loglevel 20)
  • logger.info(msg) (loglevel 20)
  • logger.confirm(msg) (loglevel 20)
  • logger.warn(msg) (loglevel 30)
  • logger.error(msg) (loglevel 40)
  • logger.fatal(msg) (loglevel 50)

logger.printMsg(msg) will always print the message without caring about the loglevel or formatting.

Set the loglevel:

logger.setFilter(level)

E.g. logger.setFilter('warn') will only print messages via logger.warn, logger.error and logger.fatal.

Options

The following options passed by vorpal.use(vorpalLogger, options) are used:

  • printDate: If this is true, the default formatters begin each message with the current date.
  • preformat: a function which is passed the message and which returns a string which should be logged instead by the default formatters. Could for example be used to render marked.

Commands

Vorpal-log adds the following (hidden) command, which simply delegates to logger.setFilter. As a user can enable debug logging with it, you might want to remove it for production.

Usage: loglevel [options] <level>


set the log level

Options:

  --help  output usage information

Customizing

logger.addFormatter(name, level, format)

Creates a logger[name] function, which will log the result of format(msg) with loglevel level. Use this to add custom formatters.

See customFormatter here for a working, insightful and useful example.

logger.setFilter(filter)

Takes either a custom filter function, a string, or a number.

When logging something, the formatter is passed to the function set by logger.setFilter. Logging only happens if this function returns true.

If logger.setFilter is passed a function, this function is the new filter function.

If passed a number, the new filter function will only log, if formatter.level is greater than or equal to that number.

If passed a string, the new filter function will only log if formatter.level is greater than or equal to formatters[filter].level.