I am looking for a way to capture the entire console dump and store it in javascript variable. I tried to set a global variable in javscript called console_output and then tried to set the valua of the variable console_output = window.console.log,however when I tried to print the console_output variable, it was empty
Asked
Active
Viewed 1,092 times
0
-
Is this something that you're logging to the console? – Robert Corponoi Sep 12 '21 at 21:39
-
Does this answer your question? [Override console.log(); for production](https://stackoverflow.com/questions/7042611/override-console-log-for-production) – kmoser Sep 19 '21 at 03:00
3 Answers
0
Try like this thing
console.logs = []
console.logWidthRecord = function(...log) {
this.logs.push(...log)
console.log(...log)
}
console.logWidthRecord('test')

eay
- 176
- 6
0
you can use such snippet:
console.stdlog = console.log.bind(console);
console.logs = [];
console.log = function(){
console.logs.push(Array.from(arguments));
console.stdlog.apply(console, arguments);
}
We bind console std and recreate log method with logs

Cucunber
- 161
- 3
0
You can redefine console.log
, while keeping a reference to the original definition. Any call to console.log
will then use the new function, in which you can do basically anything with the parameters.
The example below prints the parameters that it receives (by calling the original log function), along with some extra text. Storing the arguments somewhere is just as easily done.
const originalLog = console.log;
console.log = myLog;
function myLog() {
originalLog(">> myLog begin (length = " + arguments.length + ")");
originalLog.apply(this, arguments);
originalLog("<< myLog end");
}
console.log(1, 2, 3);
console.log("Hello World");
console.log();
console.log([true]);

Peter B
- 22,460
- 5
- 32
- 69