如何将控制台.log(对象)的输出保存到文件中?

时间:2021-09-21 16:56:37

I tried using JSON.stringify(object), but it doesn't go down on the whole structure and hierarchy.

我尝试使用JSON.stringify(对象),但它不会影响整个结构和层次结构。

On the other hand console.log(object) does that but I cannot save it.

另一方面,console.log(对象)这样做,但是我不能保存它。

In the console.log output I can expand one by one all the children and select and copy/paste but the structure is to big for that.

在控制台。log输出,我可以把所有的子都展开,然后选择复制/粘贴,但是这个结构是很大的。

8 个解决方案

#1


237  

Update: You can now just right click

更新:您现在可以右键单击。

Right click > Save as in the Console panel to save the logged messages to a file.

右击>,保存在控制台面板中,以将已记录的消息保存到一个文件中。

Original Answer:

最初的回答:

You can use this devtools snippet shown below to create a console.save method. It creates a FileBlob from the input, and then automatically downloads it.

您可以使用下面显示的devtools片段创建一个控制台。保存方法。它从输入创建一个FileBlob,然后自动下载它。

(function(console){

console.save = function(data, filename){

    if(!data) {
        console.error('Console.save: No data')
        return;
    }

    if(!filename) filename = 'console.json'

    if(typeof data === "object"){
        data = JSON.stringify(data, undefined, 4)
    }

    var blob = new Blob([data], {type: 'text/json'}),
        e    = document.createEvent('MouseEvents'),
        a    = document.createElement('a')

    a.download = filename
    a.href = window.URL.createObjectURL(blob)
    a.dataset.downloadurl =  ['text/json', a.download, a.href].join(':')
    e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null)
    a.dispatchEvent(e)
 }
})(console)

Source: http://bgrins.github.io/devtools-snippets/#console-save

来源:http://bgrins.github.io/devtools-snippets/ console-save

#2


94  

You can use "Chrome Developers Tool" Command Line API "copy()" for copying the string representation of the specified object to the clipboard.

您可以使用“Chrome开发工具”命令行API“copy()”来将指定对象的字符串表示形式复制到剪贴板。

If you have lots of objects then: You can actually "JSON.stringify()" all your objects and keep on appending them to a string. Now use copy() method to copy the complete string to clipbard.

如果您有很多对象,那么您实际上可以“JSON.stringify()”所有对象,并将它们添加到一个字符串中。现在使用copy()方法将整个字符串复制到clipbard。

#3


85  

In case you have an object logged:

如果您有一个被记录的对象:

  • Right click on the object in console and click Store as a global variable
  • 右键单击控制台中的对象,然后单击Store作为全局变量。
  • the output will be something like temp1
  • 输出将类似于temp1。
  • type in console copy(temp1)
  • 在控制台复制类型(temp1)
  • paste to your favorite text editor
  • 粘贴到您最喜欢的文本编辑器。

#4


4  

There is an open-source javascript plugin that does just that - debugout.js

有一个开放源码的javascript插件,它只做这个——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. It also toggles live-logging in one place.

Debugout。js记录和保存控制台。所以你的应用程序可以访问它们。完全披露,我写了。它可以适当地格式化不同的类型,可以处理嵌套的对象和数组,还可以在每个日志旁边放置一个时间戳。它还可以在一个地方进行实时登录。

#5


3  

right click on console.. click save as.. its this simple.. you'll get an output text file

右键单击控制台。点击另存为…它的这个简单的. .您将得到一个输出文本文件。

#6


2  

You can use library l2i (https://github.com/seriyvolk83/logs2indexeddb) to save all you put into console.log and then invoke

您可以使用library l2i (https://github.com/seriyvolk83/logs2indexeddb)来保存您的所有输入到控制台。日志,然后调用

l2i.download();

to download a file with logs.

下载一个带有日志的文件。

#7


1  

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

还有另一个开源工具可以让你保存所有的控制台。在你的服务器上的一个文件中的日志输出- JS日志刷新(插件!)

JS LogFlush is an integrated JavaScript logging solution which include:

JS LogFlush是一个集成的JavaScript日志解决方案,包括:

  • cross-browser UI-less replacement of console.log - on client side.
  • 跨浏览器UI-less替换控制台。登录客户端。
  • log storage system - on server side.
  • 日志存储系统-在服务器端。

Demo

演示

#8


0  

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).

有很多好的答案,但是为什么不直接使用JSON.stringify(your_variable)呢?然后通过复制和粘贴(删除外部引用)来获取内容。

#1


237  

Update: You can now just right click

更新:您现在可以右键单击。

Right click > Save as in the Console panel to save the logged messages to a file.

右击>,保存在控制台面板中,以将已记录的消息保存到一个文件中。

Original Answer:

最初的回答:

You can use this devtools snippet shown below to create a console.save method. It creates a FileBlob from the input, and then automatically downloads it.

您可以使用下面显示的devtools片段创建一个控制台。保存方法。它从输入创建一个FileBlob,然后自动下载它。

(function(console){

console.save = function(data, filename){

    if(!data) {
        console.error('Console.save: No data')
        return;
    }

    if(!filename) filename = 'console.json'

    if(typeof data === "object"){
        data = JSON.stringify(data, undefined, 4)
    }

    var blob = new Blob([data], {type: 'text/json'}),
        e    = document.createEvent('MouseEvents'),
        a    = document.createElement('a')

    a.download = filename
    a.href = window.URL.createObjectURL(blob)
    a.dataset.downloadurl =  ['text/json', a.download, a.href].join(':')
    e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null)
    a.dispatchEvent(e)
 }
})(console)

Source: http://bgrins.github.io/devtools-snippets/#console-save

来源:http://bgrins.github.io/devtools-snippets/ console-save

#2


94  

You can use "Chrome Developers Tool" Command Line API "copy()" for copying the string representation of the specified object to the clipboard.

您可以使用“Chrome开发工具”命令行API“copy()”来将指定对象的字符串表示形式复制到剪贴板。

If you have lots of objects then: You can actually "JSON.stringify()" all your objects and keep on appending them to a string. Now use copy() method to copy the complete string to clipbard.

如果您有很多对象,那么您实际上可以“JSON.stringify()”所有对象,并将它们添加到一个字符串中。现在使用copy()方法将整个字符串复制到clipbard。

#3


85  

In case you have an object logged:

如果您有一个被记录的对象:

  • Right click on the object in console and click Store as a global variable
  • 右键单击控制台中的对象,然后单击Store作为全局变量。
  • the output will be something like temp1
  • 输出将类似于temp1。
  • type in console copy(temp1)
  • 在控制台复制类型(temp1)
  • paste to your favorite text editor
  • 粘贴到您最喜欢的文本编辑器。

#4


4  

There is an open-source javascript plugin that does just that - debugout.js

有一个开放源码的javascript插件,它只做这个——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. It also toggles live-logging in one place.

Debugout。js记录和保存控制台。所以你的应用程序可以访问它们。完全披露,我写了。它可以适当地格式化不同的类型,可以处理嵌套的对象和数组,还可以在每个日志旁边放置一个时间戳。它还可以在一个地方进行实时登录。

#5


3  

right click on console.. click save as.. its this simple.. you'll get an output text file

右键单击控制台。点击另存为…它的这个简单的. .您将得到一个输出文本文件。

#6


2  

You can use library l2i (https://github.com/seriyvolk83/logs2indexeddb) to save all you put into console.log and then invoke

您可以使用library l2i (https://github.com/seriyvolk83/logs2indexeddb)来保存您的所有输入到控制台。日志,然后调用

l2i.download();

to download a file with logs.

下载一个带有日志的文件。

#7


1  

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

还有另一个开源工具可以让你保存所有的控制台。在你的服务器上的一个文件中的日志输出- JS日志刷新(插件!)

JS LogFlush is an integrated JavaScript logging solution which include:

JS LogFlush是一个集成的JavaScript日志解决方案,包括:

  • cross-browser UI-less replacement of console.log - on client side.
  • 跨浏览器UI-less替换控制台。登录客户端。
  • log storage system - on server side.
  • 日志存储系统-在服务器端。

Demo

演示

#8


0  

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).

有很多好的答案,但是为什么不直接使用JSON.stringify(your_variable)呢?然后通过复制和粘贴(删除外部引用)来获取内容。