I'm using in my code the angularJS service for logging ($log.error(), $log.debug(), $log.info(), etc) and it works fine.
Now, I'm trying to disable all the logs. I already tried this:
var app = angular.module('app', []);
app.config(
['$logProvider',
function ($logProvider) {
$logProvider.debugEnabled(false);
}]
);
But this does nothing, the logs continues to show...
What is the best way to disable all the angularJS logs that I put in my code?
EDIT:
I'm calling the logs like this:
(function () {
app.controller('MyController', ['$log',
function($log) {
this.testFunction = function() {
$log.debug("debug");
$log.info("info");
$log.error("error");
};
}])
})();
AngularJs includes logging service $log, which logs the messages to the browser's console. The $log service includes different methods to log the error, information, warning or debug information. It can be useful in debugging and auditing.
You should be able to run the Angular application and click on the Log Test button and see the log messages published to all publishers marked as isActive in the JSON file.
You can "override" logging methods like below (here full post):
angular.module('app', [])
.config(['$provide', function ($provide) {
$provide.decorator('$log', ['$delegate', function ($delegate) {
// Keep track of the original debug method, we'll need it later.
var origDebug = $delegate.debug;
/*
* Intercept the call to $log.debug() so we can add on
* our enhancement. We're going to add on a date and
* time stamp to the message that will be logged.
*/
$delegate.debug = function () {
var args = [].slice.call(arguments);
args[0] = [new Date().toString(), ': ', args[0]].join('');
// Send on our enhanced message to the original debug method.
origDebug.apply(null, args)
};
return $delegate;
}]);
You should also read http://blog.projectnibble.org/2013/12/23/enhance-logging-in-angularjs-the-simple-way/ to see how to create full logging provider wich you can configure on fly
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With