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

binford-slf4j

v0.0.1

Published

SLF4J-like adapter for JavaScript

Downloads

5

Readme

Binford SLF4J (for JavaScript)

Inspired by SLF4J ( http://www.slf4j.org/ ), this project aims to provide an agnostic API for all JavaScript code (both browser and node.JS server, both library and application) to use a common API interface when making log commands.

There are two parts to the binford effort:

  • SLF4J: The API that all producers of log messages should use
  • binford-logger, log4js, winston, etc.: The components that know how to consume log messages

SLF4J puts the two together.

Why SLF4J?

Because application owners should have control over what logs get written. We believe your library should not simply write to console.

Image a couple cases:

  1. Your code is deployed onto hundreds of servers. Do you want system administrators (or devops as they are now called) to have to look at each console? Wouldn't it be nice if they could hook your code up to their log shipping solution?
  2. Your code wants to warn users about deprecation. You decide to spam with a console message that is mostly seen by people who can't change it. Connect 3.0 deprecation is a shameful example, and those developers should not have written to console.

Using SLF4J you still can send as many messages as you like, but you can have confidence that your messages are only consumed if the application owner wants them.

Features

  • Producer and Consumer (log appenders) API are separate.
  • Producer API features markers and late-binding ASP.NET-like string formatting.
  • We support log4js, winston, and binford-logger out of the box.
  • Logging ouput is off by default: you have complete control in your application.
  • Default logger, the binford-logger, offers colors.

Synopsis

Once, somewhere in your code to configure how you want your logs displayed. In this example we are using the default binford-logger and configuring it to use the default appender, which in binford-logger's case goes to the color console.

var slf4j = require('binford-slf4j');
var binfordLogger = require('binford-logger');
slf4j.setLoggerFactory(binfordLogger.loggerFactory);
slf4j.loadConfig({
    level: 5,
    appenders:
	    [{
		    appender: binfordLogger.getDefaultAppender()
	    }]
});

Then, whenenver you have a message worth logging, say in users.js:

var logger = require('binford-slf4j').getLogger('company/users.js');

// ....

app = express();

app.get('/', function(req, res){
	logger.info("Received index request");
	// ...
	logger.infom(req.ip, "Looking up session {0} for ip {1}", req.session, req.ip);

	// ...
	logger.warnm(req.ip, "Session {0} for ip {1} has had 5 failures in a minute, possible abuse", req.session, req.ip);
});

Producer API

String format only:

  • error(formatString, [args]);
  • warn(formatString, [args]);
  • info(formatString, [args]);
  • debug(formatString, [args]);
  • trace(formatString, [args]);

With markers:

  • errorm(marker, formatString, [args]);
  • warnm(marker, formatString, [args]);
  • infom(marker, formatString, [args]);
  • debugm(marker, formatString, [args]);
  • tracem(marker, formatString, [args]);