https://github.com/iphands/js-client-logger
A simple framework to send JS client side errors to a remote server for persistence
https://github.com/iphands/js-client-logger
Last synced: 4 months ago
JSON representation
A simple framework to send JS client side errors to a remote server for persistence
- Host: GitHub
- URL: https://github.com/iphands/js-client-logger
- Owner: iphands
- License: gpl-2.0
- Created: 2014-04-04T15:31:50.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2014-04-07T18:58:51.000Z (over 12 years ago)
- Last Synced: 2026-03-30T23:51:52.899Z (4 months ago)
- Language: JavaScript
- Size: 180 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
js-client-logger
================
A script that logs client side JavaScript messages to a server for persistence.
By default window.onerror and JQuery ajaxErrors are intercepted, logged and then left to do their own thing.
This lets you see what errors clients run into without teaching them about various JavaScript consoles.
##Simple Usage
```
js_client_logger.init({
logger_url: "/services/logger/log"
});
```
##A logger that blacklists a User Agent
```
js_client_logger.init({
logger_url: "/services/logger/log",
skip_function: function () {
// example of how to skip certain user agents
// anything that returns true will be skipped
if (navigator.userAgent.indexOf('spider') !== -1) {
return true;
}
}
});
```
##What the payload to the server looks like
```
{
"message": {
"error_message": "Uncaught TypeError: Cannot read property 'bar' of undefined",
"script_url": "https://localhost/js-client-logger/example.html",
"line_number": 26,
"user_agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36"
},
"path": "https://localhost/js-client-logger/example.html",
"page_log_count": 1
}
```
##Example server code
Provided is a stupid simple server that writes the POST data from the JavaScript logger to disk.
I would not use this in production, but it should give you an idea of how to build a logging service into your existing web application.
To run the example:
```
$ gem install webrick
$ ruby example_server/server.rb
```
Then hit http://localhost:55555 with your browser.
Log files will be written to /tmp/js-client-logger.output by default.