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

logbro

v2.0.1

Published

Tiny logging utility with events and streams

Downloads

1

Readme

logbro · Codeship badge

There were no good names left for logging libraries, so I chose a terrible one instead.

const bro = require('logbro');
bro.warn('I have a terrible name, but I make pretty logs');

Features

  • Pretty (default), JSON, and custom formats
  • Configurable stdout and stderr streams
  • Singleton by default
  • Shared or local format and level
  • Error stack serialization

Levels

stdout

  • trace
  • debug
  • info

stderr

  • warn
  • error
  • critical

Each value implicitly includes all levels above itself – so, for example, when your app is run with NODE_DEBUG=warn node app.js, all warn, error, and critical logs will be sent to stdout/stderr. In the same example, bro.info() and bro.debug() would effectively be no-ops.

API

bro.log(level, message, [...interpolationValues])

  • level (string): one of the levels defined above
  • message (string): an optional message. If the message is a format string, it will use the interpolationValues as the format parameters.
  • [...interpolationValues] (...any): optional values to use to format the message using util.format(). Otherwise, these values will be appended to the message.

bro.<level>(message, [interpolationValues])

The same as bro.log, but without the need to pass the level as a parameter. Prefer using these to bro.log.

bro.format (Log => string)

Get the current log format OR set the current log format for this bro instance. By default, a bro instance will use the shared log format. Set bro.format = null to resume using the shared log format.

Log:

  • timestamp (string)
  • level (string)
  • message (string | undefined)

Logbro.level (string)

Get the shared log level OR set the shared log level.

Logbro.format (Log => string)

Get the shared log format OR set the shared log format.

new Logbro(opts)

opts
  • [format] (string | (Log => string))
  • [stdout] (stream.Writable)
  • [stderr] (stream.Writable)
Example
bro.log('info', 'This is an info log');

// Preferred
bro.info('This is another info log');

NOTE: bro.log has the same argument signature as console.log.

Configuration

Log Level

logbro will read the initial log level from the NODE_DEBUG environment variable.

The NODE_DEBUG environment variable can actually contain multiple flags, but the one with the lowest priority level will win. For example, NODE_DEBUG=debug,info,critical node app.js will use debug as the log level, since it automatically includes the other levels.

NOTE: If the log level is not set, logbro will not write any logs.

Log Format

logbro will read the initial log format from the LOGBRO_FORMAT environment variable.

Possible formats:

  • pretty
  • json

Events

Each log level will emit an event of the same name if the log level is high enough. For example, bro.critical('foo'); will emit a 'critical' event whose callback argument will be of type Log.

This way, applications can hook in to the logging system and respond however they want (post to Slack, send to a logging service, etc.).

Streaming

By default, logs are written to either process.stdout or process.stderr.

Apps can optionally overwrite bro.stdout and bro.stderr with other instances of stream.Writable in order to stream logs to the filesystem, via HTTP, to a database, etc.

Node.js Compatibility

logbro requires >= Node.js 8.3.

Examples

Logging
const bro = require('logbro');

bro.critical( 'this is a %s with some %s', 'log', 'formatting' );
Event binding
const bro = require('logbro');

bro.on( 'critical', msg => slack.notify( msg ) );
bro.on( 'error', (msg, log) => {
  slack.notify(msg);
  console.error(log.stack);
})
Streaming
const bro = require('logbro'),
const fs  = require('fs'),

const file = fs.createWriteStream('./log.txt');
bro.stdout = file;
bro.stderr = file;

bro.info('blah blah blah');
Custom Logbro Instance
const { Logbro } = require('logbro')
const format = log => '>> ' + log.message || 'No message';

const logger = new Logbro({ format });
logger.info('Hello world'); // ">> Hello world"