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

log4

v3.1.0

Published

Universal pluggable logging utility

Downloads

806

Readme

*nix build status Windows build status Tests coverage Transpilation status npm version

log4

(name may be subject to change)

Universal logger utility

Configurable, environment and presentation agnostic, with log levels and namespacing (debug style) support

Usage

Writing logs

// Default logger writes at 'debug' level
const log = require("log4");

// Log 'debug' level message:
log("some debug message %s", "injected string");

// Get namespaced logger (debug lib style)
log = log.get("my-lib");

// Log 'debug' level message in context of 'my-lib' namespace:
log("some debug message in 'my-lib' namespace context");

// Namespaces can be nested
log = log.get("func");

// Log 'debug' level message in context of 'my-lib:func' namespace:
log("some debug message in 'my-lib:func' namespace context");

// Log 'error' level message in context of 'my-lib:func' namespace:
log.error("some error message");

// log output can be dynamically enabled/disabled during runtime
const { restore } = log.error.disable();
log.error("error message not really logged");
// Restore previous logs visibiity state
restore();
log.error("error message to be logged");

Available log levels

Mirror of syslog (in severity order):

  • debug - debugging information
  • info - a purely informational message
  • notice - condition normal, but significant
  • warning (also aliased as warn) - condition warning
  • error - condition error
  • critical - condition critical
  • alert - immediate action required
  • emergency - system unusable

Output message formatting

log4 doesn't force any specific arguments handling. Still it is recommended to assume printf-like message format, as all available writers are setup to support it. Placeholders support reflects one implemented in Node.js format util

Excerpt from Node.js documentation:

The first argument is a string containing zero or more placeholder tokens. Each placeholder token is replaced with the converted value from the corresponding argument. Supported placeholders are:

  • %s - String.
  • %d - Number (integer or floating point value).
  • %i - Integer.
  • %f - Floating point value.
  • %j - JSON. Replaced with the string '[Circular]' if the argument contains circular references.
  • %o - Object. A string representation of an object with generic JavaScript object formatting. Similar to util.inspect() with options { showHidden: true, depth: 4, showProxy: true }. This will show the full object including non-enumerable symbols and properties.
  • %O - Object. A string representation of an object with generic JavaScript object formatting. Similar to util.inspect() without options. This will show the full object not including non-enumerable symbols and properties.
  • %% - single percent sign ('%'). This does not consume an argument.

Note to log writer configuration developers: For cross-env compatibiity it is advised to base implementation on sprintf-kit

Enabling log writing

log4 on its own doesn't write anything to the console on any other mean (it just emits events to be consumed by preloaded log writers)

To have logs written, the pre-chosen log writer needs to be initialized in main (starting) module of a process.

List of available log writers

Note: add any new writers via PR

Logs Visibility

Default visibility depends on the enviroment (see chosen log writer for more information), and in most cases is setup through following environment variables:

LOG_LEVEL

(defaults to notice) Lowest log level from which (upwards) all logs will be exposed.

LOG_DEBUG

Eventual list of namespaces to expose at levels below LOG_LEVEL threshold

List is comma separated as e.g. foo,-foo:bar (expose all foo but not foo:bar).

It follows convention configured within debug. To ease eventual migration from debug, configuration fallbacks to DEBUG env var if LOG_DEBUG is not present.

Tests

$ npm test

Project cross-browser compatibility supported by: