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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@jscv-solutions/node-logger

v1.1.0

Published

Already-configured logger for Node.js applications based on Winston.

Readme

Node.js Logger

Version NPM NPM Downloads Check Issues

Already-configured logger for Node.js applications based on Winston.

The Reason

It is really annoying to set up logging for every new Node.js project that doesn't use any framework with its built-in logger (e.g., Nest.js).

This package provides a ready-to-use logger based on Winston, configured to log messages to the console in a consistent format similar to Nest.js' logger (YYYY-MM-DD HH:mm:ss LEVEL [context] message).

[!WARNING] This project only supports console logging. If you need file logging, please refer to adding file logging.

Requirements

For Development

  • EditorConfig - Code style consistency across editors and IDEs
  • ESLint - Linting utility for JavaScript and TypeScript
  • PNPM - Fast, disk space efficient package manager
  • Prettier - Code formatter

Usage

  1. Install the Node.js Logger and Winston packages:

    # Using NPM
    npm install @jscv-solutions/node-logger winston
    
    # Using Yarn
    yarn add @jscv-solutions/node-logger winston
    
    # Using PNPM
    pnpm install @jscv-solutions/node-logger winston
  2. Import the ConsoleLogger class and use its getLogger() method in your Node.js application:

    // Using CommonJS
    const ConsoleLogger = require('@jscv-solutions/node-logger');
    const logger = ConsoleLogger.getLogger('<COMPONENT_NAME>', '<LOG_LEVEL>');
    
    // Using ES Modules
    import ConsoleLogger from '@jscv-solutions/node-logger';
    const logger = ConsoleLogger.getLogger('<COMPONENT_NAME>', '<LOG_LEVEL>');

    Note: Replace <COMPONENT_NAME> with the name of your component (e.g., 'MyApp'), and <LOG_LEVEL> with the desired log level (e.g., 'info', 'debug', 'error').

  3. Use the logger in your application:

    logger.info('This is an info message'); // YYYY-MM-DD HH:mm:ss     INFO [context] This is an info message
    logger.debug('This is a debug message'); // YYYY-MM-DD HH:mm:ss     DEBUG [context] This is a debug message
    logger.error('This is an error message'); // YYYY-MM-DD HH:mm:ss     ERROR [context] This is an error message

Configuration

Configuring Global Log Level

You can configure the global log level for all loggers by setting the LOGGING_LEVEL environment variable before starting your Node.js application:

export LOGGING_LEVEL='<LOG_LEVEL>'
node your-app.js

Replace <LOG_LEVEL> with the desired log level (e.g., 'info', 'debug', 'error').

Then, you can get loggers without specifying the log level explicitly:

// Using CommonJS
const ConsoleLogger = require('@jscv-solutions/node-logger');
const logger = ConsoleLogger.getLogger('<COMPONENT_NAME>');
// Using ES Modules
import ConsoleLogger from '@jscv-solutions/node-logger';
const logger = ConsoleLogger.getLogger('<COMPONENT_NAME>');

Setting Custom Log Level per Logger After Setting Up Global Log Level

If you want to set a custom log level for a specific logger after configuring the global log level, you can do so as follows:

// Using CommonJS
const ConsoleLogger = require('@jscv-solutions/node-logger');
const { transports } = require('winston');

const logger = ConsoleLogger.getLogger('<COMPONENT_NAME>');

logger.level = '<CUSTOM_LOG_LEVEL>';
// Using ES Modules
import ConsoleLogger from '@jscv-solutions/node-logger';
import { transports } from 'winston';

const logger = ConsoleLogger.getLogger('<COMPONENT_NAME>');

logger.level = '<CUSTOM_LOG_LEVEL>';

Using Custom Built-In Logging Levels

This package includes a custom set of levels out of the box. Why? Because verbose-related logs should be visible (even if debug logs should not appear).

This is what the custom set of levels looks like:

const customLogLevels = {
    colors: {
        error: 'red',
        warn: 'yellow',
        help: 'cyan',
        data: 'grey',
        info: 'green',
        verbose: 'cyan',
        debug: 'blue',
        prompt: 'grey',
        input: 'grey',
        silly: 'magenta'
    },
    levels: {
        error: 0,
        warn: 1,
        help: 2,
        data: 3,
        info: 4,
        verbose: 5,
        debug: 6,
        prompt: 7,
        input: 8,
        silly: 9
    }
};

The only difference from the set of logging levels from Winston is the severity for the verbose level. Everything else remains to be the same as in Winston (even the colors).

Note: The custom built-in logging levels is disabled by default.

For using this custom set of logging levels, you can either set the shouldUseCustomLogLevels parameter from the getLogger() method to true:

// Using CommonJS
const ConsoleLogger = require('@jscv-solutions/node-logger');
const { transports } = require('winston');

const logger = ConsoleLogger.getLogger('<COMPONENT_NAME>', '<LOG_LEVEL>', true);

logger.error('This is an error message'); // YYYY-MM-DD HH:mm:ss     ERROR [context] This is an error message
logger.warn('This is a warning message'); // YYYY-MM-DD HH:mm:ss     WARN [context] This is a warning message
logger.help('This is a help message'); // YYYY-MM-DD HH:mm:ss     HELP [context] This is a help message
logger.data('This is a data message'); // YYYY-MM-DD HH:mm:ss     DATA [context] This is a data message
logger.info('This is an info message'); // YYYY-MM-DD HH:mm:ss     INFO [context] This is an info message
logger.verbose('This is a verbose message'); // YYYY-MM-DD HH:mm:ss     VERBOSE [context] This is a verbose message
logger.debug('This is a debug message that will not appear');
// Using ES Modules
import ConsoleLogger from '@jscv-solutions/node-logger');
import { transports } from 'winston';

const logger = ConsoleLogger.getLogger('<COMPONENT_NAME>', '<LOG_LEVEL>', true);

logger.error('This is an error message'); // YYYY-MM-DD HH:mm:ss     ERROR [context] This is an error message
logger.warn('This is a warning message'); // YYYY-MM-DD HH:mm:ss     WARN [context] This is a warning message
logger.help('This is a help message'); // YYYY-MM-DD HH:mm:ss     HELP [context] This is a help message
logger.data('This is a data message'); // YYYY-MM-DD HH:mm:ss     DATA [context] This is a data message
logger.info('This is an info message'); // YYYY-MM-DD HH:mm:ss     INFO [context] This is an info message
logger.verbose('This is a verbose message'); // YYYY-MM-DD HH:mm:ss     VERBOSE [context] This is a verbose message
logger.debug('This is a debug message that will not appear');

Or you can configure it globally setting the SHOULD_USE_CUSTOM_LOG_LEVELS environment variable to true:

export LOGGING_LEVEL='verbose'
export SHOULD_USE_CUSTOM_LOG_LEVELS='true'
node your-app.js

Then, you can get loggers without specifying the shouldUseCustomLogLevels parameter explicitly:

// Using CommonJS
const ConsoleLogger = require('@jscv-solutions/node-logger');
const logger = ConsoleLogger.getLogger('<COMPONENT_NAME>');
// Using ES Modules
import ConsoleLogger from '@jscv-solutions/node-logger';
const logger = ConsoleLogger.getLogger('<COMPONENT_NAME>');

Adding File Logging

If you want to add file logging to the existing console logger, you can add File transport from Winston as follows:

// Using CommonJS
const ConsoleLogger = require('@jscv-solutions/node-logger');
const { transports } = require('winston');

const logger = ConsoleLogger.getLogger('<COMPONENT_NAME>', '<LOG_LEVEL>');

logger.add(new transports.File({ filename: 'app.log' }));
// Using ES Modules
import ConsoleLogger from '@jscv-solutions/node-logger';
import { transports } from 'winston';

const logger = ConsoleLogger.getLogger('<COMPONENT_NAME>', '<LOG_LEVEL>');

logger.add(new transports.File({ filename: 'app.log' }));