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

logref

v0.2.1

Published

Simple and extensible logging.

Downloads

4

Readme

logref

This is a considerable departure from the traditional logger.

This logger is meant for use in third party modules and packages. It's so that modules can have a very simple way to offer optional visibility in to the modules inner workings.

To this end, it does not have log levels like info, warn, etc. It simply allows the creation of a logger for your module (with a name) and offer a single function to take messages and a context for those messages.

This module is both an implementation and a light specification. Loggers can be quite opinionated and the creators of modules are unlikely to solidify around a single implementation of anything.

Spec

A logging library should be a single function that returns logger functions.

var logref = require('logref')
  , log = logref('mymodulename')
  ;

When running an application in a production environment, logging is the one of the few things you need to be global that is outside of node core.

Users of this specification should require the user to set the process.logging to the desired module. A library must never set this property automatically as it will override any other logger the user may want to use.

server.js

process.logging = require('logref')
var request = require('request')

Notice that this line comes before loading any other module. This is important, modules will likely check for process.logging as soon as they are required.

Using the logger is quite easy within a module.

if (process.logging) var log = process.logging('mymodule')
else var log = function () {}

...
module.exports = fancy (options) {
  log('new fancy %method for %url', options)
}
...
fancy({method:'GET', url:'http://www.google.com'})

The final piece of this spec is visible in the last example.

Log functions take two arguments, a message and a context.

Named string interpolation from the context should be supported. This prevents many errors related to using the + operator in building the message string.

logging API

The rest of this documentation covers features which should not be considered part of the specification.

Enabling stdout or stderr printing of logs.

require('logref').stdout()
require('logref').stderr()

All will print [mymodule] new fancy GET for http://www.google.com.