Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular's $log.debug() not showing on Chrome's console

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.

like image 952
Felipe Leão Avatar asked Aug 15 '17 20:08

Felipe Leão


1 Answers

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;
});
like image 199
Estus Flask Avatar answered Oct 12 '22 21:10

Estus Flask