I've decorated the AngularJS $log service, but I can only see it load the config and none of the $log methods are decorated. This used to work and I have a lot of $log.info(...);
in the application that I need to be turned off for a deploy, but even with production being set they continue to be logged to console. I abridged the methods decorated down to just info for brevity.
Can anyone see what has happened or is wrong? This is pretty textbook and when I noticed it wasn't working anymore I checked a bunch of sources and they appear to be doing it the same way.
(function () {
'use strict';
/**
* Registers a decorator for the $log service.
* @param {Object} $provide
*/
function logConfig($provide) {
console.log('CAN SEE CONFIG BOOTSTRAP');
$provide.decorator('$log', extendLogHandler);
}
logConfig.$inject = [
'$provide'
];
/**
* Turns off logging to the console based on the environment set in the configuration
* settings as long as logging was performed through AngularJS' $log component.
* @param {Object} $delegate Service instance of $log to be decorated
* @param {Object} APP_CONFIG
* @returns {Object}
*/
function extendLogHandler($delegate,
APP_CONFIG) {
// Saving the original behaviour
var _info = $delegate.info;
// Supplant existing behaviour by stipulating the application must be
// in development mode in order to log
$delegate.info = function (msg, data) {
console.log('NOT INVOKED');
// Prevent all logging unless in development
if (APP_CONFIG.ENV !== 'production') {
// Replace the original behavior
if (angular.isDefined(data)) {
_info(msg, data);
}
else {
_info(msg);
}
}
};
// Provide the supplanted $log delegate
return $delegate;
}
extendLogHandler.$inject = [
'$delegate',
'APP_CONFIG'
];
angular
.module('app')
.config(logConfig);
})();
UPDATE
Seems the issue is related to this other config that scrolls the application to the top when ngTable events occur:
function table(UtilsFactoryProvider,
ngTableEventsChannelProvider) {
// Reference to new page generation event listener
var newPageGenerationListener = null;
var ngTableEventsChannel = ngTableEventsChannelProvider.$get();
var UtilsFactory = UtilsFactoryProvider.$get();
// Subscribe to new instances of NgTableParams
ngTableEventsChannel
.onAfterCreated(function () {
// Set the previous page default for new instance
var prevPage = null;
// Deregister the any existing page generation event listener
if (typeof newPageGenerationListener === 'function') {
// Release memory to prevent leaks
newPageGenerationListener();
}
// Subscribe to new page generation event listener
newPageGenerationListener = ngTableEventsChannel
.onPagesChanged(function (events) {
// Set the next page
var nextPage = events.page();
// Only scroll to the top if not a new instance
if (prevPage !== null) {
UtilsFactory
.scrollTop(true);
}
prevPage = nextPage;
});
});
}
table.$inject = [
'UtilsFactoryProvider',
'ngTableEventsChannelProvider'
];