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

@grund/logging

v0.0.85

Published

The package exposes the following things:

Downloads

8

Readme

@grund/logging

The package exposes the following things:

  • LoggingService
    • The class that contains pretty much all logic. More about this further down.
  • Logging
    • A singleton instance of the LoggingService.
  • trace, debug, info, warn, error, fatal
    • All logging functions available in @grund/logging.
    • Originates from Logging.

LoggingService

This class contains pretty much all logic in the package. It has a few different purposes:

  1. Store logging configuration - which controls some aspects of the logging actions.
  2. Instantiate and store the logging functions
  3. Expose some utility functions (e.g. identify and groupArguments)
  4. Extend the EventService class in order to enable listener and hook functionality. This enables us to listen/hook into every logging function that is fired. Read more about this in the @grund/events documentation.

Logging functions

The logging function are listed above. All of them takes in an arbitrary number of arguments and prints them with the console.log function - prefixed with a uppercase title depending on what logging level (trace, debug, etc) is used.

All logging function also exposes a silent property. This is a function that acts the exact same way as the original function, but doesn't print anything. In other words it only fires the listeners and hooks.

Internally, all log functions are wrappers around the same functions. These wrapping functions only purpose is to create a data interface called LogOptions which is then passed to the internal functions and guides their behaviors. This interface might be good to know exists and it looks like:

interface LogOptions {
	level: LOG_LEVEL;
	isSilent: boolean;
}

Usage

import { debug, warn, error } from '@grund/logging';

debug('Hello'); // Prints "[DEBUG] Hello"
warn.silent('Foo'); // Prints nothing but fires the listeners.
error('Yolo'); // Prints "[ERROR] Yolo"

Events

As mentioned above, LoggingService implements the EventService. The event schema is the following:

namespace LoggingEventSchema {
	interface Listeners {
		log: (options: LogOptions, loggingArgs: LoggingArgs) => any;

		trace: (...args: LoggingArgs) => any;
		debug: (...args: LoggingArgs) => any;
		info: (...args: LoggingArgs) => any;
		warn: (...args: LoggingArgs) => any;
		error: (...args: LoggingArgs) => any;
		fatal: (...args: LoggingArgs) => any;

		identify: (...args: IdentifyArgs) => any;
	}

	interface Hooks {
		beforeLog: (options: LogOptions, args: LoggingArgs) => any;
		beforeIdentify: (...args: IdentifyArgs) => any;
	}
}

Worth noting is that the log listener is always fired before any of the specific log function listeners.

Usage

import { Logging } from '@grund/logging';

Logging.listeners.on('debug', () => {
	console.log('Debug fired');
});
Logging.listeners.on('log', (options, loggingArgs) => {
	console.log(`Log fired! Level: ${options.log}`);
});
Logging.hooks.on('beforeLog', (options, loggingArgs) => {
	console.log('Before log');
});

debug('Hello');

// First prints "Before log"
// Prints "Log fired! Level: debug"
// Prints "Debug fired"

Identification

In order to implement some sort of production logging or error tracking one needs to be able to identify what user is generating the logs. For this we have the identify function which is exposed by LoggingService (and, in turn, the Logging singleton). The function itself doesn't do much, but acts more as a relay and common interface to other solutions.

For instance, this is used beautifully in collaboration with the @grund/logging-sentry. This package listens to whenever you call identify and forwards it to the Sentry library. In this way you don't need to interact with the Sentry library by yourself. This functionality can of course be extended to any third party logging package.

Usage

import { Logging } from '@grund/logging';

Logging.listeners.on('identify', (userId) => console.log({ userId }));

Logging.identify(1); // Prints "{ userId: 1 }" through the listener

Configuration

The LoggingService contains a "global" property called config that determines some of the logging behavior. The current configurations are:

  • Logging.config.print.isEnabled
    • Determines if the logs should be printed with console.log.
    • Defaults to IS_DEV.
  • Logging.config.print.isGrouped
    • If true, the arguments are grouped by the types string, Error and plain object.
    • Used by other libraries (e.g. @grund/logging-sentry).
    • Defaults to false.
  • Logging.errors.shouldObjectify
    • Used when grouping the arguments (by the function Logging.groupArguments)
    • If true and any error argument contains the function toObject, call it and use the return value instead of the error itself.
    • Defaults to true
  • Logging.errors.shouldIncludeStack
    • Determines if to include the stacks when objectifying the errors.
    • Defaults to true

Usage

import { debug, Logging } from '@grund/logging';

Logging.config.print.isEnabled = false;

debug('Hello'); // Prints nothing