Created
August 14, 2013 12:46
-
-
Save markcode/6230738 to your computer and use it in GitHub Desktop.
node.js: use for debugging app using console.log and util.inspect.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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