Skip to content
Switch branches/tags
Go to file

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


AngularJS module to pass $log calls thru to Loggly

Travis CI Code Climate Coveralls


The purpose of this module is to allow you to use Loggly in your AngularJS module with as little impact to your existing code as possible.

It works by decorating AngularJS' $log service to pass calls through to Loggly. This means if you're already using $log in your app, you simply need to configure a Loggly key, and it's ready to use.

This module provides sensible defaults, but also allows you to configure it to your liking.


angular.module('myModule', ['fv.loggly-mixin'])
  .config($logglyProvider => {
    // replace with your key.  the "sensible default" is an empty string,
    // which I guess is not so sensible.    
      // this must be called to decorate the $log service.
      // if you just want the connection to Loggly established (to say, use
      // `$loggly.send()` to communicate directly), omit this.
  .run($log => {
    $'Ready to work!');
    // sends the following to Loggly:
    // {desc: 'Ready to work!'}


All configuration options (as defaults) are shown here:

angular.module('myModule', ['fv.loggly-mixin'])
  .config($logglyProvider => {
      // tracker url
      // whether to pass uncaught errors to Loggly
      // whether or not to allow Loggly to trap calls to console.error()
      // message formatting function.  accepts these two parameters
      // and should return an object.  use this to custom-tailor your
      // data.  
      // this function runs in a `null` context.
      .formatter((level, body) => {
        body.desc = body.desc || '(no description)';
        return Object.assign({level}, body);
      // mapping of new method names to original method names.
      // you can define custom "levels" in this manner, or "forward" all
      // calls from one to another.
      // if `$log.debug` doesn't exist or is disabled, `$log.log` will be used.
      // note that this function will not *remove* any existing settings;
      // $log.error() will still be $log.error() unless you override it.
        debug: 'debug',
        log: 'log',
        info: 'info',
        warn: 'warn',
        error: 'error',
        time: 'log'
      // set the level used by the $log.timeEnd() method to 'time'.
      // it should correspond to a key in the level mapping object.
      // see "Timers" section below for more info.
      // whether or not to use a domain proxy
      // add one or more tags for Loggly; one per argument

    // in addition, a convenience method exists to map a method;
    // this causes `$` to call `$log.log()`.  returns $logglyProvider
    // instance.
    $logglyProvider.mapLevel('foo', 'log');

    // finally, you can grab/modify the entire configuration object this way.
    // property `logglyConfig` is data which will be sent to Loggly; feel free
    // to manually add anything else here.
    // property `providerConfig` is used internally and does not get sent to 
    // Loggly.

    // call this when finished to decorate the service.
  .run($log => {
    // you can also pull the config at runtime

    // or send something directly to Loggly
      foo: 'bar'

String Formatting

If you don't have the luxury of ES2015 template strings, you can use the logging methods in a manner akin to console.log():

$'The %s brown fox jumped over the %s dog', 'quick', 'lazy');


Since $log has no timing functionality, and it's often useful to send timer information to Loggly, $log will now have two more functions:


Starts a timer with the given {string} label, or label __default__ if omitted.

Returns undefined.

$log.timerEnd([label], [msg], [])

Ends the timer for {string} label (using __default__ if omitted), with an optional description {string} msg and optional data {*} data. Supports formatted strings, as noted above.

Sends a message to Loggly of the following format, where {number} ms is elapsed time in milliseconds:

const msg = {
  level: 'time',
  label: label,  
  ms: ms,
  desc: desc,
  data: data

If you've used $logglyProvider.timerLevel() to set a different level value, it will be used instead of time.

Returns undefined.

$loggly Service

A $loggly service is available, however, it's mostly for internal usage. $loggly's' main responsibility is to use the configuration as defined in $logglyProvider to initiate communcation with Loggly.

The following members may be of use:


Sends {*} data directly to Loggly.

Returns undefined.


An Object representation of the configuration as set by $logglyProvider is available here. Modifying it at runtime is unsupported at the time of this writing.


Events are emitted (not broadcast) on $rootScope.

  • fv.loggly-mixin:ready: Once the Loggly tracker is "ready", this event is emitted.

  • fv.loggly-mixin:timer-started: When a timer has been started via $log.timer(), this event is emitted with the label and a timestamp (from the epoch).

  • fv.loggly-mixin:timer-stopped: When a timer has ended via $log.timerEnd(), this event is emitted with an object having the label and a ms field indicating elapsed time.



$ npm install angular angular-loggly-mixin

This package requires AngularJS 1.2.0 or higher as a peer dependency. AngularJS 2 is not supported at this time.

To use with your favorite bundling tool:

const angular = require('angular');

angular.module('myModule', [require('angular-loggly-mixin')])
  .config($logglyProvider => {


$ bower install angular

PRO TIP: Don't use Bower.


Christopher Hiller


© 2015 FocusVision Worldwide. Licensed Apache-2.0.


AngularJS module to pass $log calls thru to Loggly




No packages published