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

nn-logger

v1.0.2

Published

Functions for logging technical messages.

Readme

nn-logger

This package contains functions for logging technical messages. Messages can be logged in multiple channels at once.

The createChannel function

Creates a log channel. A log channel can be used for performing logic on records, such as, sending messages to a server. A base channel will be created at run-time. When a new channel is created the new channel will inherit all of the base channel receivers, if any.

createChannel( configuration: ChannelConfiguration ): Symbol

  • configuration: object
    • name: Symbol - The channel name (in the form of a Symbol).
    • active: Record<string, boolean> (optional) - Init enabled/disabled state of receivers. Note: all receivers, except trace, are enabled by default.
    • receivers: ReceiverContainer (optional) - The object of receivers (these receivers will override the base channel receivers). See The LogReceiverFn function.

The deleteChannel function

Delete a log channel.

deleteChannel( name: Symbol ): void

  • name: Symbol - The name of the channel.

The enableReceivers function

Enable/disable base channel receivers.

enableReceivers( receivers: Record<string, boolean> ): void

  • receivers: Record<string, boolean> - Receivers to enable/disable (e.g. { trace: true } will enable the trace receiver).

The setReceivers function

Sets base channel receivers.

setReceivers( receivers: ReceiverContainer ): void

  • receivers: ReceiverContainer - Receivers to enable/disable.

The logException function

Log an fatal message from a thrown exception.

logException( ex: unknown, message: string, ...args: unknown[] ): Error

  • ex: unknown - A value caught by a try/catch block.
  • ...args: unknown[] - The message arguments.
  • Returns the error ex.

The logFatal function

Logs a fatal message.

logFatal( er: unknown, message: string, ...args: unknown[] ): Error

  • er: Error - An error.
  • message: string - The message.
  • ...args: unknown[] - The message arguments.
  • Returns the error er.

The logError function

Logs a non-fatal error message.

logError( message: string, ...args: unknown[] ): void

  • message: string - The message.
  • ...args: unknown[] - The message arguments.

The logWarning function

Logs a warning message.

logWarning( message: string, ...args: unknown[] ): void

  • message: string - The message.
  • ...args: unknown[] - The message arguments.

The logInfo function

Logs an info message.

logInfo( message: string, ...args: unknown[] ): void

  • message: string - The message.
  • ...args: unknown[] - The message arguments.

The logTrace function

Logs an trace message.

logTrace( message: string, ...args: unknown[] ): void

  • message: string - The message.
  • ...args: unknown[] - The message arguments.

ReceiverContainer

An object of receivers.

  • fatal: LogReceiverFn
  • error: LogReceiverFn
  • warning: LogReceiverFn
  • info: LogReceiverFn
  • trace: LogReceiverFn

The LogReceiverFn function

Receiver functions will receive a log record when a message is logged.

receiver( record: LogRecord ): void

Usage


import { createChannel } from 'nn-logger';
import { enableReceivers } from 'nn-logger';
import { setReceivers } from 'nn-logger';
import { logFatal } from 'nn-logger';
import { logError } from 'nn-logger';
import { logWarning } from 'nn-logger';
import { logInfo } from 'nn-logger';
import { logTrace } from 'nn-logger';
import type { LogRecord } from 'nn-logger';

function logReceiver ( rec: LogRecord )
{
	// Do something with the log.
}

// Setup receivers.
const receivers =
{
	fatal: logReceiver,
	error: logReceiver,
	warning: logReceiver,
	info: logReceiver,
	trace: logReceiver
}

// Enable/disable base channel receivers.
enableReceivers( { fatal: true, error: true, warning: true, info: false } );
// Set the base channel receivers.
setReceivers( receivers );

// Create a channel, enable all receivers (the trace receiver is disabled by default).
// Use deleteChannel to delete a channel.
const channel = createChannel
( {
	name: Symbol( 'channel-name' ),
	active: { info: true, trace: true },
	receivers
} ); // channel = Symbol( 'channel-name' )

// Log messages.
logError( 'error-message' );
logWarning( 'warning-message' );
logInfo( 'info-message' );
logTrace( 'trace-message' );

try
{
	throw Error( 'fatal-error-message' );
} catch ( ex: unknown ) {
	// Log messages with an error.
	logFatal( ex, 'fatal-error-message' );
}

// Delete a channel.
deleteChannel( channel );