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

log-2000

v0.1.7

Published

Definitely the best logging utility...

Downloads

13

Readme

log-2000

log-2000 is the result of an attempt at creating a highly customizable logger with an interface that is easy to extend.

Installation

npm install --save log-2000

Usage

var Log = require('log-2000')

var log = Log()

log.info('Hello.')

Will print

{ level: 'info',
  date: Fri Jan 29 2016 09:25:10 GMT+0100 (W. Europe Standard Time),
  message: 'Hello.' }

Examples

Examples can be found here. Play with them on tonicdev.com/npm/log-2000 or locally by doing:

git clone https://github.com/mickvangelderen/log-2000.git
cd log-2000/examples
npm install
node basic

Customizing log-2000

With log-2000, you can customize log levels, what is being logged and where it is being logged.

The default configuration of log-2000 can be viewed in log-factory.

Customizing levels

The levels can be customized like this:

var Log = require('log-2000')

var log = Log({
  levels: [ 'my', 'own', 'levels' ]
})

log.my('hello!')

Customizing writers

These are the writers log-2000 provides:

var Log = require('log-2000')
var consoleWriter = require('log-2000/lib/console-writer')

var log = Log({
  writers: [ consoleWriter ]
})

Customizing transformers

These are the transformers log-2000 provides:

var Log = require('log-2000')
var attachDate = require('log-2000/lib/attach-date')

var log = Log({
  transformers: [ attachDate ]
})

Extending log-2000

Nowadays, extensibility is important because there are so many talented and ingenious people out there and node is being used for an increasing variety of tasks.

Creating writers

A writer is simply a function that accepts a level and data parameter. The function myWriter in the following code for example is a writer.

function myWriter(level, data) {
  console.log(level, data)  
}

For more interesting writers I recommend using the factory pattern. Check the default console writer for an example.

It would be nice if all writer factories accepted a transformers option that transforms incoming data like this:

data = transformers.reduce((d, f) => f(level, d), data)

This ensures that a user can transform the data exactly how they want for each writer. For example one might want to log human readable messages to the console and JSON lines to a file.

Creating transformers

A transformer is simply a function that accepts a level and data parameter and returns a new data object. The following code for example is a transformer.

function myTransformer(level, data) {
  return Object.assign({ level: level }, data)
}