Prefer console.error over console.log for exception logging
authorTimo Tijhof <ttijhof@wikimedia.org>
Wed, 6 Jun 2012 18:04:03 +0000 (20:04 +0200)
committerTimo Tijhof <ttijhof@wikimedia.org>
Thu, 21 Jun 2012 02:29:00 +0000 (04:29 +0200)
Follows-up:
* r112453: 268e016f08c5de6a68c25abf182d0115a6f131d5
* r88392 : bdac16978c6827bb5d8709071ee8afb99707ec3e

This way it works in both the Chrome Dev Tools and Firebug in Firefox.

Change-Id: If8b3c2747882c1e21e413f062e4c89c34144c64b

resources/mediawiki/mediawiki.js

index 66309bb..793cf22 100644 (file)
@@ -626,17 +626,21 @@ var mw = ( function ( $, undefined ) {
 
                        /**
                         * Log a message to window.console, if possible. Useful to force logging of some
-                        * errors that are otherwise hard to detect, even if mw.log is not available. (I.e.,
-                        * this logs also if not in debug mode.)
+                        * errors that are otherwise hard to detect (I.e., this logs also in production mode).
+                        * Gets console references in each invocation, so that delayed debugging tools work
+                        * fine. No need for optimization here, which would only result in losing logs.
                         *
-                        * @param msg String text for the log entry
-                        * @param e   Error [optional] to also log.
+                        * @param msg String text for the log entry.
+                        * @param e Error [optional] to also log.
                         */
                        function log( msg, e ) {
-                               if ( window.console && typeof window.console.log === 'function' ) {
+                               var console = window.console;
+                               if ( console && console.log ) {
                                        console.log( msg );
+                                       // console.error triggers the proper handling of exception objects in
+                                       // consoles that support it. Fallback to passing as plain object to log().
                                        if ( e ) {
-                                               console.log( e );
+                                               (console.error || console.log).call( console, e );
                                        }
                                }
                        }