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

wassup

v0.0.2

Published

Multi-channel logger

Downloads

12

Readme

Wassup

Logger for Node.js.

Installation

Via npm:

$ npm i wassup

Enable logging

Just import wassup to your application and call it:

require('wassup')();
// Now you have wassup.Logger instance in the GLOBAL.log.

You can provide a name for a global logger:

require('wassup')('myGlobalLog');
// Now you have wassup.Logger instance in the GLOBAL.myGlobalLog.

Also you can create you own logger instance without creating global:

var wassup = require('wassup')
  , mylog = new wassup.Logger();

or create both globals and your own:

// Import wassup and create GLOBAL.log
var wassup = require('wassup')()
// Create two local loggers
  , mylog1 = new wassup.Logger()
  , mylog2 = new wassup.Logger();
// Create one more global instance
wassup('myGlobalLog');

Channels

Channels is a named streams of log messages.

You should configure channels for each logger:

log.channel('ERR')
log.channel('WRN')
log.channel('DBG')
log.channel('AUTH')

Now you have log.ERR(), log.WRN(), log.DBG() and log.AUTH() functions that pushes log messages to their channels.

Targets

Target is a log storage. Now wassup supports two types of targets: console and file.

To see the result of logging, you must create a target and add the channels which you are interested in to it.

// Create file output target named 'debug' and add 'DBG' channel to it
log.target('debug', log.file('./debug.log')).add('DBG')
// It's a good idea to see also 'ERR' and 'WRN' channels in our debug log. Let's add it.
// We already have a configured 'debug' channel, so just take it from our logger and add the additional channels.
log.target('debug').add('ERR', 'WRN')
// Also we want to see 'AUTH' channel on our console. Let's do it.
log.target('console').add('AUTH')
// 'console' target is present on each logger by default, so we shouldn't configure it before usage.

Logging

log.ERR('Oh! There is an error here: ', err)
log.WRN('The name field is empty!')
log.DBG('Waiting connections...')
log.AUTH('User ', user, ' logged in.')

Now we have the first three messages in ./debug.log file and the last message on our console.

Add new target type

All you need is a function which takes log record object and puts it into your target. If you need any parameters for your target you can wrap this function into another.

Custom target type example:

// Let's create a target that will write to the `stderr` and optionally die after that
function stderr(die) {
  return function(data) {
    console.error(this.utils.tsToStr(data.ts), data.ch, data.msg);
    if(die) proccess.exit(1);
  }
}
// Now create two targets
log.target('stderr', stderr()).add('ERR')
log.target('die', stderr(true)).add('DIE')
// Just prints a message to stderr
log.ERR('I\'m confused...')
// Prints a message and dies
log.DIE('Harakiri!')