node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org ยป


Diagnostic logging and basic profiling using Timers

This module wrap the node.js util.log funciton with some basic level filtering and prefix the message with the and module name provided.

It also has a Timer functionnality to profile/measure the elapsed time in certain part of your code.


This module is licensed under the Apache License v2.0


npm install node-diagnostics

Include this as a module in your own project

// All diagnostics logs will be prefixed with 'MyModuleName|42|'
var diag = require('node-diagnostics').setPrefix(['MyModuleName',42]).setLevel(3); // info = 3

// Start a timer to display the elapsed time of this section of code.
var timer = diag.startTimer();

// Set the diagnostic level to INFO. Make sure that you reassign the diag
// object with the result of setLevel if you want to be able to use the
// 'diag.level' in you if condition, otherwise it will have the default
// value of 'error'!
diag = diag.setLevel(;

diag.log(diag.finest, 'Will not be shown, but the string concatenation'
                      + ' will still be done and the method called, it is'
                      + ' slower than the next invocation.');
if (diag.level >= diag.finest) diag.log(diag.finest, 'Will not be shown'
                      + ' but no method invocation and no string concatenation.'
                      + ' this is the prefered way');

if (diag.level >=   diag.log(, 'Will be shown!');
diag.log(, 'Will be shown!');

diag.log(, 'test ran in ' + timer.stop().format());