10

Recently my Chrome Browser stopped showing $log.debug() messagens on console. I have been using this way of logging with angular, instead of console.log(), across all my controllers because it is easy to disable logging when I upload my scripts to production servers.

I have already checked my $logProvider configuration and debugEnabled() is set to true.

For some reason the only way of showing $log.debug() messages on chrome is enabling verbose messages on console filter. Until recently that was not necessary. Enabling verbose isn't nice, since console spits lots of other messages that I don't care about.

I'm currently using Chrome v60.0.3112.101 64 bits on a Windows 7 machine. Is it related to browser's version? Can I do something to make it show messages again without verbose mode?

Ps.: Firefox continues showing everything as always.

0

1 Answer 1

15

console.debug log level is inconsistent between Chrome/Chromium versions. Console UI was changed in Chrome 58. Currently console.debug requires verbose level.

If other console entries are unwanted at this log level, console settings can be changed to User messages only:

console.debug

If this behaviour should be changed within particular page, console can be patched:

console.debug = console.log;

Considering that AngularJS $log service is an abstraction over console, and $log.debug was made dependent on debugEnabled state to distinguish it from $log.log, this can be fixed in less obtrusive manner in AngularJS application:

app
.config(['$provide', '$logProvider', ($provide, $logProvider) => {
  // expose a provider to reach debugEnabled in $log
  $provide.value('$logProvider', $logProvider);
})
.decorator('$log', ['$logProvider', '$delegate', ($logProvider, $delegate) => {
  // override $log.debug
  $delegate.debug = function () {
    if (!$logProvider.debugEnabled())
      return;
    $delegate.log.apply($delegate, arguments);
  }

  return $delegate;
}]);
3
  • I haven't tried the decorator option, Tested the "User messagens only" and worked as expected. Thanks! Aug 16, 2017 at 19:04
  • You're welcome. 'User messages only' will remove all other entries that have higher log level but don't result from console calls (e.g. failed requests). This may be undesirable. Aug 16, 2017 at 19:17
  • The decorator code didn't work for me, but just learning how Chrome hides logs really helped!
    – inorganik
    Oct 5, 2017 at 22:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.