Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
206 views
in Technique[技术] by (71.8m points)

javascript - 如何将console.log(object)的输出保存到文件?(How to save the output of a console.log(object) to a file?)

I tried using JSON.stringify(object) , but it doesn't go down on the whole structure and hierarchy.(我尝试使用JSON.stringify(object) ,但它并没有涉及整个结构和层次结构。)

On the other hand console.log(object) does that but I cannot save it.(另一方面, console.log(object)做到,但是我无法保存它。) 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.(在console.log输出中,我可以将所有子项一个一个地展开,然后选择并复制/粘贴,但是结构非常重要。)   ask by Eduard Florinescu translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.(您可以使用下面显示的devtools片段创建console.save方法。) It creates a FileBlob from the input, and then automatically downloads it.(它从输入中创建一个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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...