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

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


$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.


You can override the default $log behavior with a decorator to enhace the log level. This is an example:

angular.module('app').config(function($logProvider, $provide){    $logProvider.debugEnabled(false);    $provide.decorator('$log', function ($delegate) {        //Original methods        var origInfo = $delegate.info;        var origLog = $delegate.log;        //Override the default behavior        $delegate.info = function () {            if ($logProvider.debugEnabled())                origInfo.apply(null, arguments)        };        //Override the default behavior            $delegate.log = function () {            if ($logProvider.debugEnabled())                origLog.apply(null, arguments)        };        return $delegate;    });});

This was inspired from the work of John Crosby at http://www.thekuroko.com/using-angulars-log-provider/


I have faced the same issue but it's not an issue to be solved by coding instead just enable it from browser console

Go to console of browser and set level to verbose