Store console logging in Chrome in a persistent way Store console logging in Chrome in a persistent way google-chrome google-chrome

Store console logging in Chrome in a persistent way


Here's a little function that stores logs into the WebStorage (persists across browser sessions):

console.plog = function () {    var key = Date.now();    var value = JSON.stringify([].slice.call(arguments));    localStorage.setItem(key, value);    console.log.apply(console, arguments);}

To restore the logs, you'd have to run the following expression:

(function restoreLogs() {    var timestamps = Object.keys(localStorage).sort();    timestamps.forEach(function (ts) {        var logArgs = JSON.parse(localStorage.getItem(ts));        console.log.apply(console, logArgs);    });}());


If you want to automatically save everything in Chrome Console you have to run Chrome with these options:

--enable-logging --v=1

It'll save the full log of chrome inside its data directory (note that the file will be overwritten on each run). More details here.

Alternative way: install the Sawbuck utility to manage Chrome logs.


Use console.error(arg); - it will send the console message into the browser's stderr (I'm pretty sure it will do so in the release builds, too.)

Start your browser from the command line and redirect your stderr into some file (something along the lines of chrome 2>errlog).