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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@strata-js/util-logging

v1.3.1

Published

A simple logging utility, wrapping the `pino` logger.

Downloads

111

Readme

Logging Util

This is a basic logging library that wraps the pino logging library. All this adds is some useful utility libraries, as well as changing the default behavior of the logger to comply with the console.* api. (Meaning, when you pass multiple arguments, those objects are serialized and appending to the log message. In pino, those objects are added to the json logging payload.)

This project is under the Strata.js family, and it is included as a part of @stratajs/strata. We provide it as an external dependency, because logging is a commonly needed piece of functionality, and it's often desirable to have all code using the same logger.

You can find this logger exported from strata as:

import { logging } from '@strata-js/strata';

// Create a logger
const logger = logging.loggerFor(module);

Installation

This utility package is published to the public npm repository. Simply do:

// npm
$ npm add @strata-js/util-logging

// yarn
$ yarn add @strata-js/util-logging

Usage

Basic Usage

Using the logger is very simple:

import { logging } from '@strata-js/util-logging';

const logger = logging.getLogger('myLogger');

// [0:00:00 AM] INFO (service): Hello World {"foo":"bar"}
logger.info('Hello', 'World', { foo: 'bar' });

Advanced Usage

Configuration

The logger supports two possible pieces of configuration; level and prettyPrint. They are defined as follows:

  • level - One of trace, debug, info, warn, error, or critical. This log level and above will be logged.
  • prettyPrint - If true, will run through pino-pretty. (Only takes effect with dev packages installed.)

In order to set the configuration, call setConfig() and pass the new configuration. The configuration will take effect once an attempt is made to log to the logger. It will not update loggers that have already been logged to.

import { logging } from '@strata-js/util-logging';

logging.setConfig({ prettyPrint: false });
const logger = logging.getLogger('myLogger');

// {"level":30,"time":1622349751673,"pid":10170,"hostname":"Hades","name":"service","msg":"Hello World {\"foo\":\"bar\"}"}
logger.info('Hello', 'World', { foo: 'bar' });
Disabling Logging

In order to disable logging, simply set the minimum logging level to silent:

import { logging } from '@strata-js/util-logging';
logging.setConfig({ level: 'silent', prettyPrint: false });

// All logging from this point on will not show up

const logger = logging.getLogger('myLogger');
logger.error('This will not log!');

Logging Levels

The following levels are available:

  • trace
  • debug
  • info
  • warn
  • error
  • critical
  • silent

These can be found on the logger object, as functions.

import { logging } from '@strata-js/util-logging';

const logger = logging.getLogger('myLogger');

logger.trace('The `trace` level');
logger.debug('The `debug` level');
logger.info('The `info` level');
logger.warn('The `warn` level');
logger.error('The `error` level');
logger.critical('The `critical` level');
logger.silent('The `silent` level');    // This is a no-op and will not log anything.