Skip to content

Instantly share code, notes, and snippets.

@markcode
Created August 14, 2013 12:46
Show Gist options
  • Save markcode/6230738 to your computer and use it in GitHub Desktop.
Save markcode/6230738 to your computer and use it in GitHub Desktop.
node.js: use for debugging app using console.log and util.inspect.
var LOGGING = 'debug'; // debug, alert, silent.
function _log(a,b){"debug"===LOGGING&&void 0!==b?console.log("debug - "+a+" > "+require("util").inspect(b,!0,99,!0)):"debug"===LOGGING&&void 0===b?console.log(a):"alert"===LOGGING&&console.log(a)};
// use for debugging
var LOGGING = 'debug'; // debug, alert, silent.
function _log(msg, dump) {
if ( LOGGING === 'debug' && dump !== undefined ) {
console.log('debug - ' + msg + ' > ' + require('util').inspect(dump, true, 99, true));
} else if ( LOGGING === 'debug' && dump === undefined ) {
console.log(msg);
} else if ( LOGGING === 'alert' ) {
console.log(msg);
} else {
}
}
// use
var examine = {};
examine.id = 101;
examine.text = "hello";
examine.arr = ["one", "two", "three"];
_log('hello world', examine);
/*
debug - hello world > { id: 101,
text: 'hello',
arr:
[ 'one',
'two',
'three',
[length]: 3 ] }
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment