JavaScript Logging

You can send your Javascript logs to Loggly using our script loggly-jslogger. You can send both plaintext and JSON logs from any webpage. It’s also able to capture JavaScript errors from the window and send them to Loggly. For alternatives, please see the Advanced Options section.

JavaScript Logging Setup

  1. Include the JavaScript tracker
  2. Drop the following snippet into your web page, at the top or bottom

    <script type="text/javascript" src="http://cloudfront.loggly.com/js/loggly.tracker-2.1.min.js" async></script>
    <script>
      var _LTracker = _LTracker || [];
      _LTracker.push({
        'logglyKey': 'TOKEN',
        'sendConsoleErrors' : true,
        'tag' : 'loggly-jslogger' 
      });
    </script>
    

    Replace:

    Note: Setting ‘sendConsoleErrors’ to true will send all the unhandled errors to Loggly. It also leaves previously defined ‘window.onError’ functions. In case, you want to send unhandled errors during the page load, remove the aysnc attribute from the script tag and place the script tag at the top of your Web page.

  3. Try Sending Logs
  4. Send some test data using these examples.

    Plaintext:

    _LTracker.push('Hello World');
    

    JSON:

    _LTracker.push({
        'text': 'Hello World',
        'aList': [9, 2, 5],
        'anObject': {
            'id': 1,
            'value': 'foobar'
        }
    });
    

  5. Verify Events
  6. Search Loggly for events for tag as loggly-jslogger over the past 20 minutes. It may take a few minutes to index the event. If it doesn’t work, see the troubleshooting section below.

    tag:loggly-jslogger

    loggly_jslogger

Advanced JavaScript Logging Options

  • GitHub or Bower – You can also host this library on your own site by copying the source, or fork it for your own needs
  • Proxy Setup – Setup proxy for Ad blockers.
  • Tracking Pixel – A tracking pixel if you can only do GET requests
  • Loggly Libraries Catalog – New libraries are added to our catalog
  • Search or post your own JavaScript logging service or how to log JavasScript questions in the community forum.

Troubleshooting JavaScript Logs

If you don’t see any data show up in the verification step, then check for these common problems.

    Check script:

  • Wait a few minutes in case indexing needs to catch up
  • Open the developer tools console in your browser to verify the script is loaded and the _LTracker object is successfully initialized
  • Still Not Working?

  • Check if there are any Ad blockers are active on your browser.
  • Search or post your own questions for JavaScript logging and configuration around server side log messages, output, and more in the community forum.
Thanks for the feedback! We'll use it to improve our support documentation.


Top