Save the console.log in Chrome to a file


Does anyone know of a way to save the console.log output in Chrome to a file? Or how to copy the text out of the console?

Say you are running a few hours of functional tests and you've got thousands of lines of console.log output in Chrome. How do you save it or export it?

All Answers
  • Translate

    I needed to do the same thing and this is the solution I found:

    1. Enable logging from the command line using the flags:

      --enable-logging --v=1

      This logs everything Chrome does internally, but it also logs all the console.log() messages as well. The log file is called chrome_debug.log and is located in the User Data Directory.

    2. Filter the log file you get for lines with CONSOLE(\d+).

    Note that console logs do not appear with --incognito.

  • Translate

    Good news

    Chrome dev tools now allows you to save the console output to a file natively

    1. Open the console
    2. Right-click
    3. Select "save as.."

    save console to file

    Chrome Developer instructions here.

  • Translate

    There is an open-source javascript plugin that does just that, but for any browser - debugout.js

    Debugout.js records and save console.logs so your application can access them. Full disclosure, I wrote it. It formats different types appropriately, can handle nested objects and arrays, and can optionally put a timestamp next to each log. You can also toggle live-logging in one place, and without having to remove all your logging statements.

  • Translate

    I have found a great and easy way for this.

    1. In the console - right click on the console logged object

    2. Click on 'Store as global variable'

    3. See the name of the new variable - e.g. it is variableName1

    4. Type in the console: JSON.stringify(variableName1)

    5. Copy the variable string content: e.g. {"a":1,"b":2,"c":3}

    enter image description here

    1. Go to some JSON online editor: e.g.

    enter image description here

  • Translate

    This may or may not be helpful but on Windows you can read the console log using Event Tracing for Windows

    Our integration tests are run in .NET so I use this method to add the console log to our test output. I've made a sample console project to demonstrate here:

    --enable-logging --v=1 doesn't seem to work on the latest version of Chrome.

  • Translate

    For better log file (without the Chrome-debug nonsense) use:

    --enable-logging --log-level=0

    instead of --v=1 which is just too much info.

    It will still provide the errors and warnings like you would typically see in the Chrome console.

  • Translate

    A lot of good answers but why not just use JSON.stringify(your_variable) ? Then take the contents via copy and paste (remove outer quotes). I posted this same answer also at: How to save the output of a console.log(object) to a file?

  • Translate

    There is another open-source tool which allows you to save all console.log output in a file on your server - JS LogFlush (plug!).

    JS LogFlush is an integrated JavaScript logging solution which include:

    • cross-browser UI-less replacement of console.log - on client side.
    • log storage system - on server side.


  • Translate

    If you're running an Apache server on your localhost (don't do this on a production server), you can also post the results to a script instead of writing it to console.

    So instead of console.log, you can write:

    JSONP('http://localhost/save.php', {fn: 'filename.txt', data: json});

    Then save.php can do this

     $fn = $_REQUEST['fn'];
     $data = $_REQUEST['data'];
     file_put_contents("path/$fn", $data);

  • Translate

    These days it's very easy - right click any item displayed in the console log and select save as and save the whole log output to a file on your computer.