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

universal-log

v0.3.10

Published

Flexible logger for Node.js and the browser

Downloads

17

Readme

UniversalLog Build Status

Flexible logger for Node.js and the browser.

Installation

npm install --save universal-log

Usage

import UniversalLog from 'universal-log';

let logger = new UniversalLog({ appName: 'example' });

logger.info('Little info');
logger.error('There is something wrong');

Concepts

Levels

There are 10 levels of logging: silence, trace, debug, info, notice, warning, error, critical, alert and emergency.

Depending on the type of output, a level can have an effect on the way a log message is formated. For example, the ConsoleOutput uses different colors for each levels.

A muteLevels option allows to mute some levels. By default, the silence level is muted. The trace and debug levels are also muted when NODE_ENV is undefined or equal to 'development'.

Outputs

You can configure where you want to output your log messages.

For now, the supported outputs are:

It is easy to create your own type of output. An output is just an object with a write(logName, hostName, level, message) method. See an example of custom output.

API

new UniversalLog([options])

Create a logger.

import UniversalLog from 'universal-log';

let logger = new UniversalLog({ appName: 'example' });

options

  • logName: the name of the log. If not specified, the name is a combination of appName and NODE_ENV.
  • appName: the name of the running application.
  • hostName: the name of the host where the application is running. If not specified, hostName is determined from the hostname of the machine. If the application is running in a browser, hostName defaults to 'browser'.
  • outputs: the outputs where all the logging goes. The default is an instance of ConsoleOutput.
  • muteLevels: mute the specified levels. By default, the silence level is muted. The trace and debug levels are also muted when NODE_ENV is undefined or equal to 'development'.
  • decorators: a simple way to "decorate" log messages. A decorator is a function receiving a string (a log message) and returning a string (the decorated log message). Decorators are useful to add some contextual information to log messages. For example, a decorator could be used to add the name of the current user.

logger.log(level, messsage)

Log a message with the specified level.

logger.log('info', 'Little info');
logger.log('warning', 'There is something wrong');

logger.{level}(messsage)

Convenient shorthand methods to log messages for a specific level.

logger.debug('Little info');
logger.error('There is something wrong');
logger.warning('Be careful, something is happening');

logger.createTimer([label])

Measure and log the time passed doing something.

let timer = logger.createTimer('Heavy computation');
// ...
timer.stop();

logger.addOutput(output)

Add an output to the logger.

import { RemoteOutput } from 'universal-log';

logger.addOutput(new RemoteOutput('http://api.example.com/v1'));

logger.addDecorator(decorator)

Add a decorator to the logger.

logger.addDecorator(function(message) {
  return message + ` (current user: ${username})`;
});

License

Who cares?