I want to decorate the output of console.log under Node.js like following codes
var console = { log: function(text) { global.console.log('Test: ' + text); } }; console.log('custom console is here'); Output:
Test: custom console is here
However, if I remove the var before the variable console,
console = { log: function(text) { global.console.log('Test: ' + text); } }; console.log('custom console is here'); The output will be
custom console is here
I know the console will become the global variable when the var is deleted. Based my understanding, it will override the global.console, but it seems not. Why the global.console cannot be override?
The second question: Is there any better way to custom console.log?
global.console = .., notconsole = ..