Last active
August 3, 2016 04:38
-
-
Save CatTail/2b7755719c1b73f052759d28b57b18f0 to your computer and use it in GitHub Desktop.
A little console wrapper to log with filename and line number (without console.log('xxxxx') anymore)
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
$ node test.js | |
at Object.<anonymous> (/Users/cattail/workspace/upyun/choppe/test.js:3:9) hello | |
at Object.<anonymous> (/Users/cattail/workspace/upyun/choppe/test.js:5:9) world |
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
require('./xxxx') | |
console.log('hello') | |
console.log('world') |
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 isProduction = process.env.NODE_ENV === 'production' | |
var methods = ['log', 'info', 'warn', 'error'] | |
if (!isProduction) { | |
methods.forEach(function (method) { | |
var original = console[method] | |
console[method] = function() { | |
var error = new Error() | |
stack = error.stack.split('\n') | |
var args = [].slice.call(arguments) | |
args.unshift(stack[2].trim()) | |
original.apply(console, args) | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment