Monday, May 20, 2024
13
rated 0 times [  19] [ 6]  / answers: 1 / hits: 124495  / 11 Years ago, thu, november 7, 2013, 12:00:00

I would like to put a button in my app, if you press it it will get the contents of everything that was written to the console and email it to me (for reporting bugs). I know I can keep a variable around and every time I do a console.log also append the message to that variable but I am trying to keep the memory consumption of the app low so it would be much more efficient just to grab it from the console.


Is there a way to retrieve the console messages from javascript?


More From » google-chrome

 Answers
14

You can't. What's in the console can't be read from JavaScript.



What you can do is hook the console.log function so that you store when it logs :



console.stdlog = console.log.bind(console);
console.logs = [];
console.log = function(){
console.logs.push(Array.from(arguments));
console.stdlog.apply(console, arguments);
}


console.logs contains all what was logged. You can clean it at any time by doing console.logs.length = 0;.



You can still do a standard, non storing, log by calling console.stdlog.


[#74423] Wednesday, November 6, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
braeden

Total Points: 231
Total Questions: 96
Total Answers: 86

Location: Somalia
Member since Mon, Dec 28, 2020
3 Years ago
;