Skip to content

aronvaughan/angular-logging

Repository files navigation

angular-logging

angular lib for logging, wraps $log and allows logging thresholds and categories via a simple config

Getting Started

Download the production version or the development version.

  1. Include the angular-logging.js script provided by this component into your app's webpage.

In your web page:

<script src="angular.js"></script>
<script src="bower_components/angular-logging/angular-logging.min.js"></script>
<script src="scripts/app.js"></script>
  1. Add avaughan.logging as a module dependency to your app.

In your app.js:

angular.module('myApp', ['avaughan.logging']);
  1. [optional] configure the log settings

In you app.js:

   /**
    * configure the logging infrastructure
    */
   myApp.config(function(avLogProvider, avLevel) {

       var myLogConfig = {
           //set a default log level - this will be used if someone logs under a category that is not defined below
           loglevel: avLevel.INFO, //TRACE, DEBUG, INFO, WARN, ERROR
           //these are the configured channels for logging - each channel can have it's own threshold
           //only log statements above the threshould will be output to the underlying $log
           category: {
               testDebugCategory: avLevel.DEBUG,
               testErrorCategory: avLevel.ERROR,
               testController: avLevel.WARN
           }
       };
       avLogProvider.$get().setConfig(myLogConfig);
       //in other projects - this works, TODO find out why
       //avLogProvider.$get[1]().setConfig(myLogConfig);
       //there is now a convenience method: return AVaughanLogging.get(avLogProvider, myLogConfig);
   });
  1. Use it!

In your javascript:

  • pass in 'avLog' as a dependency
  • create a logger with a specific channel (each channel can have it's own logging threshold)
  • log like the wind!
angular.module('myApp').controller('testController', ['$scope', 'avLog',
    function($scope, avLog) {
        var logger = avLog.getLogger('testController');
        logger.warn("this is a warning !!!!", {someObject: "a test object"}); //this will be logged - the configured level is WARN
        logger.debug("this is a debug statement [should be hidden!!!]]"); //this will not be logged - the configured level is WARN
    }
]);

Documentation

Log Levels

the available log levels (used in config) are:

DEBUG
INFO
WARN
ERROR

Examples

See getting started See also tests in this github project

Changelog

v 0.0.4

  • updated config to be more forgiving of when the initalization calls (it can drop the config depending on where it is hooked up in the client project
  • fixed defect where config changes after initialization aren't picked up by the logger (it now looks for the level config so it gets the latest)

TODO

  • add .logger.ifEnabled checks to avoid processing time on log statements that are under the current configured threshold
  • add the concept of appenders (i.e. allow writing to other sinks beside $log - could allow for server side posting of errors, rum/perf tagging, etc..)

Resources

initial grunt workspace generated by angular-component

Contributing

download the full source....

  1. install npm and grunt
  2. cd to root of project checkout

to test

  1. grunt test

to see the example app

  1. grunt serve
  2. make sure you have developer tools/firebug, etc.. open so you can see console logs

About

angular lib for logging, wraps $log and allows logging thresholds and categories via a simple config

Resources

Contributing

Stars

Watchers

Forks

Packages

No packages published