angular lib for logging, wraps $log and allows logging thresholds and categories via a simple config
Download the production version or the development version.
- 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>
- Add
avaughan.logging
as a module dependency to your app.
In your app.js:
angular.module('myApp', ['avaughan.logging']);
- [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);
});
- 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
}
]);
the available log levels (used in config) are:
DEBUG
INFO
WARN
ERROR
See getting started See also tests in this github project
- 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)
- 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..)
initial grunt workspace generated by angular-component
- http://stackoverflow.com/questions/19614545/how-can-i-add-some-small-utility-functions-to-my-angularjs-application
- http://stackoverflow.com/questions/15666048/angular-js-service-vs-provider-vs-factory
- http://briantford.com/blog/angular-bower
download the full source....
- install npm and grunt
- cd to root of project checkout
to test
- grunt test
to see the example app
- grunt serve
- make sure you have developer tools/firebug, etc.. open so you can see console logs