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

loggero

v2.1.0

Published

Lightweight stream based logger

Downloads

69

Readme

loggero

Lightweight stream based logger

Examples

A few examples can be found here.

API

Logger comes with a default logger instance called global.

create(name, options)

Factory method to create loggers with a particular name. Options are

  1. enabled [boolean] - Flag to create the logger in a enabled/disabled state. Default - true.
  2. stream [WritableStream] - Stream to write messages to. If a stream isn't provided, the global logger's stream will be used, which defaults to console. Default - undefined.
  3. level [levels] - Minimum level for messages to be logged. If a level isn't provided, the global logger's level will be used, which defaults to info. Default - undefined.
var loggero = require('loggero');

var logger = loggero.create('OhWoW', {
  enabled: false,
  level: loggero.levels.warn
});

levels

levels are enums that represent a threshold for logging messages. Meaning, that only messages of equal or higher level will be logged. The lowest level is info and the highest level is error. If custom levels are used, they will follow the same processing logic for determing if a particular message should be logged. For custom levels, you will need to specfy values higher than error which is 3.

The different values are

  1. info - alias log.
  2. warn.
  3. error.

The following example we configure the global logger to log warnings and errors. Also a few messages are logged to illustrate the logging interface.

var logger = require('loggero');

logger
  .level(logger.levels.warn)
  .log('Message 1')
  .warn('Warning 1')
  .error('Error 1');

find(name)

Method to find a logger by name.

In the example below, we search for the logger called OhWoW, configure its logging level, and log a few messages.

var logger = require('loggero');

logger
  .find('OhWoW')
  .level(logger.levels.info)
  .log('Message 1')
  .warn('Warning 1')
  .error('Error 1');

pipe(stream)

Method to setup the stream the logger writes to. Currently, a logger can only have one stream.

The example below shows how the default global logger is piped to JSONStream, and then piped to process.stdout. The output format is JSONLines.

var JSONStream = require('JSONStream');
var logger = require('loggero');

logger
  .pipe(JSONStream.stringify(false))
  .pipe(process.stdout);

logger
  .warn('A warning', 'cup cakes are low')
  .error('An error', 'cup cakes ran out', 'buy more')
  .log('message 12');

write(level, data)

Generic method to log messages. Call this if you are looking to write messages with a custom level. This method is what logger uses internally to log messages, warnings, and errors.

log(message, ...)

Method to log info messages.

info(message, ...)

Alias for the log method. Use whichever is more suitable for your taste.

warn(message, ...)

Method to log warnings.

error(message, ...)

Method to log errors.

enable()

Method to enable message logging.

disable()

Method to disable messages logging.

only()

Method to quickly disable ALL logger but the logger only() was called on. Only one logger can be set to only. If one is already set to only, the call is a noop.

all()

Method that removes the only filter.

enableAll()

Method to enable all loggers; global enable. When this is called, all logger will log. only and level will still determine whether or not a logger instance can actually log a message.

disableAll()

This disables the global enable flag. If this is called, then no logger will be able to log messages of any kind.

level(level)

Minimum level a message must have in order to be logged. For example, if the current level is warn, the only warn and error will be logged. Please see levels for the list of values.

Licensed under MIT