Have ideas to improve npm?Join in the discussion! »

    TypeScript icon, indicating that this package has built-in type declarations

    2.0.12 • Public • Published


    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");


    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

         errors_on_std_error: true

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

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

    Categories can be changed also with

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


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

    The log levels allowed can be found


    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:


    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


    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




    npm i pm2-logwrapper

    DownloadsWeekly Downloads






    Unpacked Size

    25.4 kB

    Total Files


    Last publish


    • avatar