简体   繁体   English

如何在Large SPA中处理和记录Javascript中的错误

[英]How to handle and log error in Javascript in Large SPA

I am new to Javascript , I was wonder like we log error in Server Side programming language in a error.log file . 我是Java语言的新手,我想知道我们是否将错误以服务器端编程语言记录在error.log文件中。 for example in PHP there we can set a error file to log the errors . 例如在PHP中我们可以设置一个错误文件来记录错误。

Is there a way to do this in Large SPA in Javascript or we just log in console using 是否可以使用Javascript在大型SPA中执行此操作,或者我们只使用以下方法登录控制台

console.log()

I have this simple app which loads some json data from API and I have just used the normal alert and console.log methods to show error I would like to know whats the best way to do this. 我有一个简单的应用程序 ,可以从API加载一些json数据,而我只是使用普通的alert和console.log方法显示错误,我想知道什么是最好的方法。

I understand that I can write a Web Service which can be called every time an error being thrown and using the 我了解我可以编写一个Web Service ,每次抛出错误并使用该错误时都可以调用该服务。

window.error or element.error function probably I can send error report to the server where I will write on a log file. window.errorelement.error函数可能可以将错误报告发送到将在日志文件上写入的服务器。

But is Doing rest call on every error thrown is a good way? 但是,对抛出的每个错误进行休息调用是一个好方法吗?

Thanks 谢谢

Browsers won't allow you to write on a file in client so You have to use ajax and write a log on server. 浏览器不允许您在客户端中写文件,因此您必须使用ajax并在服务器上写日志。 Sending errors to server using ajax is a good solution. 使用ajax将错误发送到服务器是一个很好的解决方案。 Also throwing error with alert is not appreciated by any user. 此外,任何用户都不会理解带有警报的抛出错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何处理console.log和JavaScript中的错误输出? - How to handle console.log and error output in JavaScript? 如何在JavaScript库中处理大量HTML - How to handle large amount of HTML in a javascript library REST API:安全处理Java SPA中的身份验证 - REST API: Securely Handle Authentication in a Javascript SPA 如何选择特定用户登录Azure AD中的Java SPA? - How can I Choose Specifc Users to Log Into my Javascript SPA in Azure AD? 如何在javascript中处理大型文本文件需要切片算法 - How to handle a large text file in javascript need a slicing algorithm 如何在Javascript或Jquery中使用多个循环处理大量数组? - How to handle a large numbers of arrays with multiple loops in Javascript or Jquery? 如何使用javascript处理大型html文本页面? - How to handle large html text page using javascript? 如何在Javascript中避免使用“Infinity”和console.log中的大量数据? - How to avoid “Infinity” and console.log a large number in Javascript? 尝试 plot 图形时如何处理 javascript 中的日志(0) - how to handle log(0) in javascript when trying to plot a graph 如何处理不活跃的用户并在 JavaScript 中将他们注销? - How to handle inactive users and log them out in react JavaScript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM