Globally disabling $log.debug in Angular 1.4.2

Question!

I have an angular app that is logging debug messages in the console using $log.debug. The app is increasing in size, so I wanted to see if there was a way to globally disable these log files when deployed in production. I saw a few posts where you can configure the $logProvider to disable logging debugs to the console ($logProvider.debugEnabled(false);), but this does not work for me. Here is one of my controllers where I added this:

(function () {
    'use strict';

    angular
        .module('bodyShop')

        // This config was added to globally disable logs
        .config(function($logProvider){
            $logProvider.debugEnabled(false);
        })

        .controller('CustomerController', function ($log, $window) {

         var vm = this;
         ...
         ...
         ...
         ...
         ...

This does not throw any errors and the page works as expected, but I can still see all the debug logs in the console.

Also, I know this will only "globally" disable logs in this controller. But I also tried to add the $logProvider config in my module so that I can disable logs across my entire app, but with no success.

Any advice would be helpful.



Answers

There is only one $logProvider in an app regardless of how many modules so setting debugEnabled once would be global across all modules that are injected

The only explanation would be that it is being set somewhere else in another config that runs after the one shown



You can use a decorator to override the default logging behaviour. There is an article by John Crosby at http://www.thekuroko.com/using-angulars-log-provider/

Here is some code that will do the job from answer How to turn on/off $log.debug in AngularJS I haven't run it, but I think it's what you are looking for

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;
    });
});
By : Mike King


based on the structure of the example, it's likely that webCrtPartList is NOT the managed entity. You need to use the response of EntityManager.merge() to get the managed entity (the parameter to EntityManager.merge() will not [necessarily] be managed)



This video can help you solving your question :)
By: admin