![]() ![]() $.With the widespread acceptance of web standards, and the resulting deprecation of browser prefixes, there has been a noticeable change in the browser market. Here’s what it might look like using jQuery: Whenever it fires, we make an Ajax request to the server, passing along the details of the error message. In essence, what we need to do for our purposes is listen for the window.onerror event. Karl Dubost has written an excellent article about exactly what window.onerror is and how it behaves it’s certainly worth a read. Whenever JavaScript encounters an error, it fires the window.onerror event you can listen for this event, either to attempt to recover from the error or, in our case, log the error message. Then, if a user reports a problem you have something to go on - look through the logs to see what errors people are having on that particular page, and you will probably find your problem more efficiently. Instead, we send it to the server and collate it together with all the other errors your users have encountered in a file or database. ![]() The principle is quite simple: when the browser encounters an error, or when a developer makes a call to console.log or similar functions, we don’t just log the error in the console on the client-side. Surely, in this day and age, we have to be able to do this in a much smarter way? There is a way, with client-side logging If you have even a tiny bit of experience as a developer, you’ll know that this kind of thing happens all the time. pptx file that your client inevitably sends you. What about when things break down on the user’s side? What browser were they using? What is their screen resolution? What is the actual error? An error message would sure be useful at this point - way better than that screenshot embedded in a. How many times have you gotten an email from a client saying that a user had a problem with a particular page, but nothing further. This is all well and good, but the problem is that these are only useful when you’re the one developing/investigating the issue. And developer tools such as Opera Dragonfly or Chrome dev tools offer more sophisticated debugging environments, with features such as breakpoints and watches. Enter console.log(): our informative new friend literally changed the way we debugged our code. “I had no choice,” you counter… “how else was I to know why it wasn’t working?”ĭon’t worry… the best of us have done it too! We’ve all used the dreaded alert() at some point in our lives. So what about the front-end?Īdmit it… you’ve all used an alert statement when trying to debug client-side JavaScript before. Here we see that there was a problem with our wp_commentmeta table on the 16th of May 2012 (120516) at 13:57 and that we need to run a MySQL repair on it. Server-side logs vary in how they look depending on the system in question, but just to give you a few examples: A server access log (IP Addresses have been obfuscated):ġ20516 13:57:39 /usr/sbin/mysqld: Table './wordpress/wp_commentmeta' is marked as crashed and should be repaired In this article we will take you in detail through the rather useful concept of client-side logging, a method of recording client-side errors and alerts on the server and making them much easier to work through. Traditionally, hunting down errors on your client-side code hasn’t been as efficient or elegant as on the server-side, often relying on hawkish little alert outputs embedded in your code. Values coming out of the database wrong? Look at the database logs to see if there’s a syntax error hiding around there. Requests to your website timing out? Check the web server’s logs and see if there’s anything in there. ![]() Server-side errors are usually easy to track down. For decades, programmers have been using error logging to find out what they did wrong when their code isn’t working.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |