[英]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.error
或element.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.