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

ni-logging

v1.0.3

Published

JavaScript message logging system

Downloads

19

Readme

NI Logging

Yet another JS message logging system.

Features

  • Logs numbering
  • Predefined log levels: DEBUG, INFO, WARN, ERROR, FATAL
  • Custom log levels support
  • Multiple log targets
  • Logging errors
  • Log configuration per target
  • Filtering log entries

Code Example

Setup

const logConfigurationDev = [
    {
        target: new ConsoleTarget(),
        level: LogLevel.ALL
    }
];
Log.configuration = logConfigurationDev;

Usage

const logger = Log.getLogger(MyClass);

logger.debug('Debug message');
logger.info('Info message');
logger.warn('Warn message');
logger.error('Error message');
logger.fatal('Fatal error message');
logger.log(500, 'Custom level message');

try {
    saveDraft();
} catch (error) {
    logger.warn.withError(error, 'Saving draft failed');
}

try {
    login();
} catch (error) {
    let logEntry = logger.error.withError(error, 'Login failed');
    window.alert(`Log-in failed. See log #${logEntry.logNumber} for details`);
}

Installation

npm i ni-logging --save

Demo

Download demo from the Download section

or clone Demo project

API Reference

Log

Log object manages configuration, log targets and loggers. Use it to obtain a logger instance:

Log.getLogger(source, category)

Arguments:

  • source (mandatory) is an object for which you create a Logger. Usually it's a class or constructor, but it can be any named function that would want to log messages or string.
  • category (optional) is an additional parameter that can be used for filtering. It is intended to describe a functionality, group of functionalities (e.g. network, localization, settings) or a module of a larger platform (e.g. AccountsManager)

Example:

class Foo {
    constructor(parameter) {
        const logger = Log.getLogger(Foo);
        logger.info('Instance of Foo created with parameter', parameter);
    }
}

Set Log.configuration to overwrite default configuration.

Example:

let logCollection = [];

const logConfig = {
    DEV: [
        {
            target: new ConsoleTarget(),
            level: LogLevel.ALL,
            ignoredCategories: ['communication']
        },
        {
            target: new ArrayTarget(logCollection),
            level: LogLevel.ALL
        }
    ],
    UAT: [
        {
            target: new ConsoleTarget(),
            level: LogLevel.WARN
        },
        {
            target: new ArrayTarget(logCollection),
            level: LogLevel.ALL
        }
    ],
    PROD: [
        {
            target: new ConsoleTarget(),
            level: LogLevel.WARN
        },
        {
            target: new ArrayTarget(logCollection),
            level: LogLevel.INFO
        },
        {
            target: new ServiceTarget(logCollection),
            level: LogLevel.DEBUG
        }
    ]
}

Log.configuration = logConfig.DEV;

To keep your logs consistent, configuration should be set at application initialization and from that point should not be changed.

Configuration entry description:

  • target - log target to send messages to. ni-logger is shipped with ConsoleTarget and ArrayTarget. See Creating custom log target to find out how to create your own one.
  • level - specifies min message level - all messages with specified level or higher will be logged to given target. See LogLevel for the list of predefined levels.
  • ignoredSources - array of filters. All messages sent by Logger with a source that matches any of the filters will be ignored.
  • ignoredCategories - Same rule as for ignoredSources but for categories.
  • acceptedSources - array of filters. Contains exceptions from the ignoredSources filters.
  • acceptedCategories - array of filters. Contains exceptions from the ignoredCategories filters.

Filters

Filter can be

  • string - test
  • RegExp - new RegExp('^test')
  • function - function (value) { return value.length > 10; }

LogLevel

Log level is a number.

LogLevel object provides predefined log levels:

  • LogLevel.ALL = 0
  • LogLevel.DEBUG = 100
  • LogLevel.INFO = 200
  • LogLevel.WARN = 300
  • LogLevel.ERROR = 400
  • LogLevel.FATAL = 1000

Logger

Logger provides you with an interface to log messages with a given level.

Examples:

// First get an instance:
const logger = Log.getLogger(SampleSource);
logger.log(LogLevel.DEBUG, 'Message to be logged');

The above has same effect as:

logger.debug('Message to be logged');
logger.info('Message to be logged');
logger.warn('Message to be logged');
logger.error('Message to be logged');
logger.fatal('Message to be logged');

Every method from above can be extended to log an error:

logger.warn.withError(error, 'Message to be logged');

This is useful to log handled exceptions:

try {
    // [...]
} catch (error) {
    logger.warn.withError(error, 'Message to be logged');
}

Every Logger method return a log entry. This can be used to integrate logging with user notifications:

try {
    saveForm(content);
} catch (error) {
    let logEntry = logger.error.withError(error, 'Error while saving form', content);
    notificationMechanism.notify(`Could not save the form. See log number #${logEntry.logNumber} for technical details.`);
}

What's included?

Extending

You can easily extend package features:

Tests

Run tests with npm test

License

MIT