angularjsloggingangularjs-log

How to turn on/off $log.debug in AngularJS


I'm trying to use $log.debug("Foo"). How can it be turned on off. I can't find a sample anywhere. I think it need to be set in the config, but I cant seem to get that to work either.

Where does one set the on and off switch?


Solution

  • $logProvider.debugEnabled(true)

    This is only available in AngularJS 1.1.2 or later.

    https://github.com/angular/angular.js/pull/1625

    Here is an example of it being set.

    var app = angular.module('plunker', []);
    
    app.config(function($logProvider){
      $logProvider.debugEnabled(true);
    });
    
    app.controller('MainCtrl', function($scope, $log ) {
      $scope.name = 'World';
      $scope.model = {value: "test"};
      $log.debug('TEST Log');
    });
    

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

    By default it is on.