Skip to content
Ferron H edited this page Apr 13, 2015 · 1 revision

##How to Use

######Step 1. Add Module Dependency

var app = angular.module('myAngularApp', ['log.ex.uo']);

######Step 2. Enable Logging Globally to see logs

Add the logExProvider dependency to your AngularJS app to configure logging. Pass true to the logExProvider.enableLogging(boolean) function as a parameter to enable logging. This is set to false by default to disable logging in a production environment. The Best practice is to keep this flag set to false in the master version of the code base, given that some version control system is being used. See eg. below.

app.config(['logExProvider', function(logExProvider) {
    logExProvider.enableLogging(true);
}]);

To enable logging quietly (Without printing the config message) a second param can be passed in the to the logExProvider.enableLogging(boolean,boolean) function

app.config(['logExProvider', function(logExProvider) {
    var enabledLogging=true, enableQuietly=true;
    logExProvider.enableLogging(enabledLogging, enableQuietly);
}]);

######Step 3. Print Log from any component (Controller, Directive etc..)

app.controller('CoreController', ['$scope','$log', function($scope, $log) {
    $log.log("Simple Log Extender Example");
}]);

######Step 4. Load the web page and look in the Developer Console Sample Output

Dec-08-2013-12:50:52PM >>  CONFIG: LOGGING ENABLED GLOBALLY
Dec-08-2013-12:50:52PM >>  Simple Log Extender Example

Advanced: Create custom $log instances with extra functionality

The following snippet shows you the full use of a method log-ex provides with the $log service when injected into your angular components ($controller, $directive, etc.). It should be reassigned to the $log service which creates a new instance specific to the component. Please continue with the documentation to see more Advanced Use Cases to show you practical uses of the configurations. The snippet below explains what each parameter is used for.

app.controller('CoreController', ['$scope','$log', function($scope, $log) {
     /*
     * @param {String=} className - Name of object in which $log.<function> calls are invoked.
     * @param {boolean=} override - activates/deactivates component level logging
     * @param {boolean=} activateTemplates - enables/disables the template engine
     * @param {String=} colorCss - css styles for coloring/styling log outputs,
     *                             will be applied to all log methods
     */
    $log = $log.getInstance(className, override, activateTemplates, colorCss);
}]);