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

pm2-logwrapper

v2.0.12

Published

log wrapper around console.log / console.error to implements different log category and levels

Downloads

4

Readme

pm2-logwrapper

log wrapper around console.log / console.error to implements different log levels and categories. Useful when used with pm2 and/or docker

Create logger

const logger = require('pm2-logwrapper')();

Create logger with specific category

const logger = require('pm2-logwrapper')("MY_CUSTOM_CATEGORY");

or

const logger = require('pm2-logwrapper')().getLogger("MY_CUSTOM_CATEGORY");

By default the logger is initialized with this set of options

let opts = {
    errors_on_std_error: false,
    add_timestamp: false,
    add_process: true,
    add_category: true,
    timestamp_format: "yyyy-mm-dd HH:MM:ss",
    default_category : "default",
    categories: {
        "default": "INFO"
    }
};
  • errors_on_std_error: if true will print ERROR and FATAL logs also on standard error. By default is false and will print these logs only on standard out.
  • add_timestamp: if true will prepend the current timestamp to each log message. By default is false because PM2 can do it
  • add_category: if true the category will be written in the log message as [<category_name>]. By default is true
  • add_process: if true the process identifier will be written in the log message as [process_id]. By default is true. For master process will be [Master] and for worker process will be ["Worker-1"]
  • timestamp_format: used to format the current timestamp, if add_timestamp is enabled. By default is "yyyy-mm-dd HH:MM:ss"
  • default_category: is the name of the default category if none is specified. By default is "default"
  • categories: object of each category you need to use with this logger. By default only "default" category is defined

You can specify different set of options by passing them to the init method. The object passed will be merged with the default configuration, so you don't need to specify every options, but only the options you need to change

logger.init({
     errors_on_std_error: true
});

To Specify different categories you can initialize the library with an object like.

logger.init({
    "categories": {
        "myCustomCategory1": logger.getLevels().DEBUG,
        "myCustomCategory2": logger.getLevels().TRACE
    }
});

Categories can be changed also with

logger.setCategory(logger.getLevels().INFO, "myCustomCategory1");

or

logger.setCategories( {
     "myCustomCategory1": logger.getLevels().DEBUG,
     "myCustomCategory2": logger.getLevels().TRACE
});

The log levels allowed can be found

logger.getLevels();

and the available values are:

{
    OFF: "OFF",
    FATAL: "FATAL",
    ERROR: "ERROR",
    WARN: "WARN",
    INFO: "INFO",
    DEBUG: "DEBUG",
    TRACE: "TRACE"
}

The logging method, for each level are:

logger.info("myMessage");

This method will use the default category log level for this logger instance. By default is default unless specified in the constructor or with getLogger method

logger.info("myMessage","myCustomCategory");

This method will use myCustomCategory category log level for this logger instance

Each log level has a corresponding method to check if the log level is enabled

logger.isInfoEnabled();
logger.isInfoEnabled("myCustomCategory");