$logProvider debug logging default off from AngularJS 1.5
0 reputation · 26 Sept 2022, 19:32 UTC
0 reputation · 26 Sept 2022, 19:32 UTC
AngularJS 1.5 changed the default for $logProvider.enableDebugLogging from true to false. In 1.4 and earlier, $log.debug calls from Angular internals and third-party modules were emitted by default, which increased console volume. From 1.5 onward the flag defaults to false and debug output is suppressed unless explicitly enabled in the module config phase.
The configuration is set with $logProvider.enableDebugLogging during config and cannot be changed at runtime without reinitializing the application. The change reduces notification noise but also removes diagnostic output that some modules emit via $log.debug.
For a codebase transitioning from 1.4 to 1.5+, the goal is to keep useful alerts visible in development and testing while avoiding console noise in production. The config-phase restriction and reliance of third-party code on $log.debug create an unresolved decision about visibility versus noise.
Under what conditions is enableDebugLogging considered appropriate for non-production builds? How does the config-phase-only restriction affect visibility of diagnostics from dynamically loaded modules? Can disabling debug logging obscure non-debug warnings from third-party modules that use $log.debug for operational messages?
32775 reputation · 27 Sept 2022, 07:02 UTC
In AngularJS 1.5, $logProvider.enableDebugLogging defaults to false. This change suppresses $log.debug() calls from both the framework internals and third-party modules to reduce console noise. Because this is a provider configuration, it must be set during the module config phase; it cannot be toggled at runtime.
Enabling debug logging is appropriate for non-production builds under the following conditions:
The config-phase restriction means that any module loaded dynamically (e.g., via lazy loading or asynchronous script injection) will inherit the global $logProvider state established at application bootstrap. If enableDebugLogging was set to false during the initial config phase, diagnostics from dynamically loaded modules using $log.debug will remain invisible.
Regarding operational messages: Yes, disabling debug logging can obscure critical information. Some third-party modules incorrectly use $log.debug for operational alerts or state changes that are not strictly "debug" in nature. If a module uses $log.debug instead of $log.warn or $log.error for important notifications, those messages will be silenced by default in 1.5+.
To enable debug logging for development environments while keeping it disabled for production, use a conditional check during the config phase:
angular.module('myApp', [])
.config(['$logProvider', function($logProvider) {
// Replace with your environment detection logic
if (window.env === 'development') {
$logProvider.enableDebugLogging(true);
}
}]);
To verify the current state of the logger in the browser console, you can inject the $log service via the Angular debug tool or a temporary controller:
// In the browser console (assuming angular is global)
angular.element(document.body).injector().get('$log').debug('Debug logging is active');
If no output appears, debug logging is disabled.
Diagnostic Detail Required: Are you using a custom wrapper for the $log service or a third-party logging library (like ngLog)? This may override the $logProvider settings.
Use comments to ask for clarification. Post a solution as an answer.
32,775 reputation · 27 Sept 2022, 06:11 UTC
In AngularJS 1.5+ the $logProvider.debugEnabled flag only controls the $log.debug method; $log.info, $log.warn, and $log.error remain unaffected and will still appear in the console regardless of the flag’s value.
Because the flag is read‑only after the injector is created, it must be set during the module’s config phase. A common pattern is to read an environment constant (e.g., window.__ENV__) and call $logProvider.debugEnabled(true) only when that constant indicates a non‑production build.
angular.module('app').config(['$logProvider', function ($logProvider) {
if (window.__ENV__ === 'dev' || window.__ENV__ === 'test') {
$logProvider.debugEnabled(true);
}
}]);