Skip to content

Commit

Permalink
[BUGFIX lts] Avoid console.trace for every Ember.warn
Browse files Browse the repository at this point in the history
Originally (Ember < 3.2), `Ember.warn` used `Ember.Logger` as an
abstraction layer in case `console` was not present. Since
`Ember.Logger` was deprecated in
[emberjs/rfcs#297](https://emberjs.github.io/rfcs/0297-deprecate-ember-logger.html)
the internals have been refactored to use `console` directly instead.

When that change was made, the following:

```js
    Logger.warn(`WARNING: ${message}`);
    if ('trace' in Logger) {
      Logger.trace();
    }
```

Was changed to:

```js
    console.warn(`WARNING: ${message}`);
    if (console.trace) {
      console.trace();
    }
```

This _seems_ correct, however when you dig into it you will notice that
the `Ember.Logger` class **never** had a `.trace` method! The reason for
the original `'trace' in Logger` check was specifically so that you
_could_ do `Ember.Logger.trace = () => console.trace` _IIF_ you wanted
to see where a given warning was coming from. That was added back in
2012, but since then the developer tools of modern browsers have gotten
massively better. At this point, **every** `console.log`/`console.warn`
tracks its stack trace so that you can drill into the source in the dev
tools. The primary difference between that functionality and calling
`console.trace()` directly like this is that with `console.warn`
the stack trace is hidden by default (and has to be manually expanded),
whereas with `console.trace()` it is _always_ called and the full stack
is printed.

Ultimately, this means that when we refactored to address the
`Ember.Logger` deprecation, we began calling `console.trace` for _every_
`Ember.warn` invocation and the `console.trace()` calls make the console
fairly unusable even with a very low volumn of warnings.
  • Loading branch information
rwjblue committed Dec 20, 2018
1 parent c17f0a6 commit 3e45eb9
Showing 1 changed file with 0 additions and 3 deletions.
3 changes: 0 additions & 3 deletions packages/@ember/debug/lib/warn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ if (DEBUG) {
registerHandler(function logWarning(message) {
/* eslint-disable no-console */
console.warn(`WARNING: ${message}`);
if (console.trace) {
console.trace();
}
/* eslint-enable no-console */
});

Expand Down

0 comments on commit 3e45eb9

Please sign in to comment.