Coder Social home page Coder Social logo

brennon / angular-loggly-logger Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ajbrown/angular-loggly-logger

0.0 2.0 0.0 163 KB

An AngularJS module which sends your $log message to loggly, and provides a service for manually sending messages to loggly.

JavaScript 93.24% HTML 6.76%

angular-loggly-logger's Introduction

Build Status Coverage Status Join the chat at https://gitter.im/ajbrown/angular-loggly-logger

Angular Loggly Logger is a module which will decorate Angular's $log service, and provide a LogglyLogger service which can be used to manually send messages of any kind to the Loggly cloud log management service.

Getting Started

LogglyLogger can be installed with bower:

bower install angular-loggly-logger

Once configured (by including "logglyLogger" as a module dependency), the $log service will automatically be decorated, and all messages logged will be handled as normal as well as formated and passed to LogglyLogger.sendMessage. The plain text messages are sent into the "json.message" field with the decorated log while custom JSON objects are sent via "json.messageObj" field as Loggly only supports one type per field.

To use both the decorated $log and the LogglyLogger service, you must first configure it with an inputToken, which is done via the LogglyLoggerProvider:

angular.module( 'myApp', ['logglyLogger'] )

  .config( function( LogglyLoggerProvider ) {
    LogglyLoggerProvider.inputToken( '<loggly input token here>' );
  } );

  .run( function( LogglyLogger, $log ) {

    //This will be sent to both the console and Loggly
    $log.info( "I'm a little teapot." );

    //This will be sent to loggly only
    LogglyLogger.sendMessage( 'Short and Stout.' )
  }

$log decoration

When sent through the $log decorator, messages will be formatted as follows:

// Example: $log.warn( 'Danger! Danger!' );
{
  level: "WARN",
  timestamp: "2014-05-01T13:10Z",
  msg: "Danger! Danger!",
  url: "https://github.com/ajbrown/angular-loggly-logger/demo/index.html",
}

// Example: $log.debug( 'User submitted something:', { foo: 'A.J', bar: 'Space' } )

{
  level: "DEBUG",
  timestamp: "2014-05-01T13:18Z",
  msg: ["User submitted something", { foo: 'A.J.', bar: 'Space' }],
  url: "https://github.com/ajbrown/angular-loggly-logger/demo/index.html",
}

However, 'url' and 'timestamp' are not included by default. You must enable those options in your application config (see below).

Note that if you do not call LogglyLoggerProvider.inputToken() in a config method, messages will not be sent to loggly. At the moment, there is no warning -- your message is just ignored.

Configuration

The following configuration options are available.

  LogglyLoggerProvider

    // set the logging level for messages sent to Loggly.  Default is 'DEBUG',
    // which will send all log messages.
    .level( 'DEBUG' )

    // set the token of the loggly input to use.  Must be set, or no logs
    // will be sent.
    .inputToken( '<your-token>' )

    // set whether or not HTTPS should be used for sending messages.  Default
    // is true
    .useHttps( true )

    // should the value of $location.absUrl() be sent as a "url" key in the
    // message object that's sent to loggly?  Default is false.
    .includeUrl( false )

    // should the current timestamp be included? Default is false.
    .includeTimestamp( false )

    // set comma-seperated tags that should be included with the log events.
    // Default is "angular"
    .inputTag("angular,customTag")

    // Send console error stack traces to Loggly.  Default is false.
    .sendConsoleErrors( false )

    // Toggle logging to console.  When set to false, messages will not be
    // be passed along to the original $log methods.  This makes it easy to
    // keep sending messages to Loggly in production without also sending them
    // to the console.   Default is true.
    .logToConsole( true )

Sending JSON Fields

You can also default some "extra/default" information to be sent with each log message. When this is set, LogglyLogger will include the key/values provided with all messages, plus the data to be sent for each specific logging request.

  LogglyLoggerProvider.fields( { appVersion: 1.1.0, browser: 'Chrome' } );

  //...

  $log.warn( 'Danger! Danger!' )

  >> { appVersion: 1.1.0, browser: 'Chrome', level: 'WARN', message: 'Danger! Danger', url: 'http://google.com' }

Extra fields can also be added at runtime using the LogglyLogger service:

  app.controller( 'MainCtrl', function( $scope, $log, LogglyLogger ) {
    
    logglyLogger.fields( { username: "foobar" } );
    
    //...
    
    $log.info( 'All is good!' );
    
  >> { appVersion: 1.1.0, browser: 'Chrome', username: 'foobar', level: 'WARN', message: 'All is good', url: 'http://google.com' }
  }

Beware that when using setExtra with LogglyLogger.sendMessage( obj ), any properties in your obj that are the same as your extra will be overwritten.

Contributing

Contributions are awesome, welcomed, and wanted. Please contribute ideas by opening a new issue, or code by creating a new pull request. Please make sure your pull request targets the "develop" branch.

angular-loggly-logger's People

Contributors

ajbrown avatar ggregoire avatar varshneyjayant avatar vhalbwachs avatar willmcclellan avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.