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

lugg

v3.0.0

Published

A simple logging module that uses pino and draws inspiration from TJ Hollowaychuk's debug.

Downloads

3,906

Readme

lugg

Build Status

A simple logging module that uses pino and draws inspiration from TJ Hollowaychuk's debug.

Logging is a universal concern in most programs, and lugg aims to make the common usage pattern as simple as possible.

Manifesto: Server logs should be structured. JSON's a good format. Let's do that. A log record is one line of JSON.stringify'd output.

Based on pino

At first glance, logging appears to be an isolated concern, but on closer inspection you can see that it intersects with analytics, error handling, debugging and disaster recovery. The pino module provides a great solution to address all of these concerns.

lugg simplifies the common use case, and aims to be really simple to use.

Inspired by debug

lugg also provides the ability to control debug output using a DEBUG environment variable.

Example Usage

// call init once in your program
require('lugg').init();

// then in foo.js
var log = require('lugg')('foo');
log.info('doing stuff');
log.warn({foo: 'bar'}, 'something %s', 'interesting');
log.error(new Error('blah'), 'something %s', 'bad');
log.debug('this will not be output'); // set DEBUG=app:foo to see debug output from this logger

Arguments

Each argument you pass is logged as-is, up to the first string argument, which is formatted using util.format() to provide string interpolation of any subsequent arguments.

Controlling Log Output

Read the source (it's tiny) and refer the pino docs for more info.

You can control the output of lugg using the level option:

require('lugg').init({level: 'warn'}); // show only warnings and higher

The logging level you provide in the call to .init() would typically come from your local configuration (eg. warn in production, info in development).

You can also manipulate the logging level for specific loggers at runtime, without having to modify your configuration, using an environment variable (see Controlling Debug Output below).

The call to lugg.init() takes an option hash, which is passed to pino.child() to create a "root logger". All loggers returned from lugg are children of this root logger, so they inherit whatever settings you provide to init().

See the docs for pino for more info about the supported options. lugg will provide a name of "app" if no name is provided.

Controlling Debug Output

The log level can be manipulated using the DEBUG environment variable, using the same approach as the debug module:

$ DEBUG=* node app.js # print all debug output
$ DEBUG=app:* node app.js # print debug output from your app
$ DEBUG=foo,express:* node app.js # print debug output from foo and express
$ DEBUG=*,-foo node app.js # print all debug output except foo

As loggers are created, if they have a name that matches this environment variable then they will have their level set to debug. You can also manipulate this programmatically using lugg.debug():

lugg.debug('app:foo'); // debug messages from app:foo
lugg.debug('app:foo:'); // debug messages from app:foo

Be aware this doesn't change any loggers that have already been created.

Output

pino writes logs to stdout in JSON format, so pipe the output through the pino-pretty CLI to get logs in a more human readable format:

node app.js | pino-pretty