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 🙏

© 2026 – Pkg Stats / Ryan Hefner

sm-log

v2.1.0

Published

This module provide easy log color output with different log levels

Downloads

12

Readme

NodeJS smart log module

This module provide easy log color output with different log levels.

Installation

Installation via npm:

$ npm install sm-log --save

Log levels

  • error: the system is in distress, customers are probably being affected (or will soon be) and the fix probably requires human intervention. The "2AM rule" applies here- if you're on call, do you want to be woken up at 2AM if this condition happens? If yes, then log it as "error".

  • warn: an unexpected technical or business event happened, customers may be affected, but probably no immediate human intervention is required. On call people won't be called immediately, but support personnel will want to review these issues asap to understand what the impact is. Basically any issue that needs to be tracked but may not require immediate intervention.

  • info: things we want to see at high volume in case we need to forensically analyze an issue. System lifecycle events (system start, stop) go here. "Session" lifecycle events (login, logout, etc.) go here. Significant boundary events should be considered as well (e.g. database calls, remote API calls). Typical business exceptions can go here (e.g. login failed due to bad credentials). Any other event you think you'll need to see in production at high volume goes here.

  • debug: just about everything that doesn't make the "info" cut... any message that is helpful in tracking the flow through the system and isolating issues, especially during the development and QA phases. We use "debug" level logs for entry/exit of most non-trivial methods and marking interesting events and decision points inside methods.

  • trace: we don't use this often, but this would be for extremely detailed and potentially high volume logs that you don't typically want enabled even during normal development. Examples include dumping a full object hierarchy, logging some state during every iteration of a large loop, etc.

Usage

var log = require('./lib/sm-log');

//your file or module name
var m = 'MyModule';

//setting 'trace' log level
log.level('T');

//demo data
var current_data = {hello: 'world'};

//with sm-log you can output
//different string info
log.trace('trace message');

//sm-log can output not just 
//string but objects too
log.debug(current_data);

//you can set module or 
//file name in log output
log.info('info message', m);

//you can output date and time
//when event happend
log.showDate(true);
log.warn('warning message', m);
log.showDate(false);

//you can output line number
//where log function was called
log.showDate(true);
log.warn('warning message', m);
log.showDate(false);

//you can output error message and call
//callback of function

function readSomeFile(cb){
	var fs = require('fs');
	fs.readFile('/some/file.txt', function(err, data){
		if(err) return log.error(err, m, cb);
		log.info('file read done', m, cb);
	})
}
readSomeFile(function(){});

Output:

[T]: trace message
[D]: {"hello":"world"}
[I][MyModule]: info message
[05/28/2015 1:29:28 PM][W][MyModule]: warning message
[E][MyModule]: {"errno":-2,"code":"ENOENT","path":"/some/file.txt"}

You can use different function formats for calling log:

//error msg
log.error('error msg');
log.err('error msg');
log.e('error msg');

//warning msg
log.warning('warning msg');
log.warn('warning msg');
log.w('warning msg');

//info msg
log.info('info msg');
log.i('info msg');

//debug msg
log.debug('debug msg');
log.d('debug msg');

//trace msg
log.trace('trace msg');
log.t('trace msg');

You can use event handler for catch log events from different part of you code:

log.on('log', function(log_data){
	console.log(JSON.stringify(log_data));
})

Contacts

Jaroslav Khorishchenko [email protected]