Saturday, December 21, 2013

AngularJS Logging

AngularJS has a logging service $log that can be used to log information for e.g. debugging purpose. The main advantage of using this instead of the usual "console.log" is that you can control whether debug level messages are filtered out. Additionally, you can also add decorators to add additional behaviours.

To use it, just inject "$log" as you would $scope, $location etc.

Example here: http://docs.angularjs.org/api/ng.$log

Configure the $logProvider when defining the module to enable/disable debug.

Example: http://plnkr.co/edit/HZCAoS?p=preview

Example of decorator to add additional behaviour: https://coderwall.com/p/_zporq

No comments:

Post a Comment