Created
September 15, 2015 04:10
-
-
Save mksoni88/03f69c9c40bb65aa8bbb to your computer and use it in GitHub Desktop.
Override console.log to print line number ( and filename ) (sometimes helpful in nodejs debugging)
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
_log = console.log; | |
global.console.log = function() { | |
var traceobj = new Error("").stack.split("\n")[2].split(":"); | |
var file = traceobj[0].split(process.env.PWD + '/')[1]; | |
var line = traceobj[1]; | |
var new_args = [file + ":" + line + " >>"]; | |
new_args.push.apply(new_args, arguments); | |
_log.apply(null, new_args); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice trick but the
stack
property of enError
object is tagged as "Non-standard". I would check ifError("").stack
returns asundefined
and work around with a default fallback if it is.