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

loglevelnext

v6.0.0

Published

A modern logging library for Node.js and modern browsers that provides log level mapping to the console

Downloads

1,891,877

Readme

tests cover size

loglevelnext

loglevelnext is a modern logging library for Node.js and modern browsers, written with modern patterns and practices which provides log level mapping of the console object.

For browser use, or use in client-side applications, loglevelnext should be bundled by your preferred bundler or compiler, such as Rollup.

Getting Started

First thing's first, install the module:

npm install loglevelnext --save

Usage

Users can choose to use loglevelnext in Node.js or in the client (browser).

const log = require('loglevelnext');

log.info('bananas!');

Log Levels

By default loglevelnext ships supporting the following log level name-value pairs:

{
  TRACE: 0,
  DEBUG: 1,
  INFO: 2,
  WARN: 3,
  ERROR: 4,
  SILENT: 5
}

Default Logger

When requiring loglevelnext in Node.js the default export will be an instance of LogLevel wrapped with some extra sugar.

Methods

Please see LogLevel for documentation of all methods and properties of every log instance, including the default instance.

trace, debug, info, warn, error

These methods correspond to the available log levels and accept parameters identical to their console counterparts. e.g.

console.info('...');
console.info('...');
// ... etc

create(options)

Returns a new LogLevel instance. The options parameter should be an Object matching the options for the LogLevel constructor.

Note: LogLevel instances created are cached. Calling create with a previously used name will return the cached LogLevel instance. To create a different instance with the same name, assign a unique id property to the options parameter.

Properties

factories

Type: Array [ Class ]

Returns an Array containing the factory classes available within loglevelnext to outside modules. Particularly useful when creating plugins. eg.

const log = require('loglevelnext');
const { MethodFactory } = log.factories;
class MyFactory extends MethodFactory { ... }

loggers

Type: Array [ LogLevel ]

Returns an Array containing references to the currently instantiated loggers.

Factories aka Plugins

If you're used to using plugins with loglevel, fear not. The same capabilities are available in loglevelnext, but in a much more straightforward and structured way. loglevelnext supports by way of "Factories." A Factory is nothing more than a class which defines several base methods that operate on the console and provide functionality to a LogLevel instance. All factories must inherit from the MethodFactory class, and may override any defined class functions.

For an example factory, please have a look at the PrefixFactory which provides similar functionality as the loglevel-prefix plugin, and is the factory which is used when a user passes the prefix option to a LogLevel instance.

Browser Support

As mentioned, loglevelnext is a logging library for Node.js and modern browsers, which means the latest versions of the major browsers. When bundling or compiling loglevelnext for use in a browser, you should ensure that appropriate polyfills are used. e.g. Internet Explorer typically requires polyfilling both Symbol and Object.assign.

Attribution

This project originated as a fork of the much-loved loglevel module, but has diverged and has been rewritten, and now shares similarities only in functional intent.

Base Log SVG by Freepik from www.flaticon.com.

Meta

CONTRIBUTING

LICENSE (Mozilla Public License)