Save the console.log in Chrome to a file

2019-01-01 11:00发布

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?

9条回答
若你有天会懂
2楼-- · 2019-01-01 11:02

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.

Demo

查看更多
其实,你不懂
3楼-- · 2019-01-01 11:07

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.

查看更多
不再属于我。
4楼-- · 2019-01-01 11:07

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. https://jsoneditoronline.org/

enter image description here

查看更多
忆尘夕之涩
5楼-- · 2019-01-01 11:11

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?

查看更多
荒废的爱情
6楼-- · 2019-01-01 11:14

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.

查看更多
只若初见
7楼-- · 2019-01-01 11:16

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.

查看更多
登录 后发表回答