Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
14
rated 0 times [  21] [ 7]  / answers: 1 / hits: 19708  / 13 Years ago, tue, february 14, 2012, 12:00:00

Is it possible to extend the console object?



I tried something like:



Console.prototype.log = function(msg){
Console.prototype.log.call(msg);
alert(msg);
}


But this didn't work.
I want to add additional logging to the console object via a framework like log4javascript and still use the standard console object (in cases where log4javascript is not available) in my code.



Thanks in advance!


More From » logging

 Answers
76

Try following:



(function() {
var exLog = console.log;
console.log = function(msg) {
exLog.apply(this, arguments);
alert(msg);
}
})()

[#87472] Monday, February 13, 2012, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
blaynetheoi

Total Points: 146
Total Questions: 116
Total Answers: 103

Location: India
Member since Thu, Apr 8, 2021
3 Years ago
;