mediawiki.log: Introduce mw.log.error
authorTimo Tijhof <krinklemail@gmail.com>
Wed, 22 Apr 2015 21:58:06 +0000 (22:58 +0100)
committerOri.livneh <ori@wikimedia.org>
Thu, 23 Apr 2015 04:20:57 +0000 (04:20 +0000)
In addition to mw.log.warn, but for the console.error channel.

Change-Id: I7b09a75da6c985a9e0cc73591f49b21972efd393

resources/src/mediawiki/mediawiki.js
resources/src/mediawiki/mediawiki.log.js
tests/qunit/data/testrunner.js

index ee57c21..237157c 100644 (file)
                                }
                        };
 
+                       /**
+                        * Write a message the console's error channel.
+                        *
+                        * Most browsers provide a stacktrace by default if the argument
+                        * is a caught Error object.
+                        *
+                        * @since 1.26
+                        * @param {Error|string...} msg Messages to output to console
+                        */
+                       log.error = function () {
+                               var console = window.console;
+                               if ( console && console.error && console.error.apply ) {
+                                       console.error.apply( console, arguments );
+                               }
+                       };
+
                        /**
                         * Create a property in a host object that, when accessed, will produce
                         * a deprecation warning in the console with backtrace.
index ad68967..053fb1a 100644 (file)
@@ -79,6 +79,7 @@
 
        // Restore original methods
        mw.log.warn = original.warn;
+       mw.log.error = original.error;
        mw.log.deprecate = original.deprecate;
 
 }( mediaWiki, jQuery ) );
index 3c44b55..3dd2af6 100644 (file)
         * </code>
         */
        QUnit.newMwEnvironment = ( function () {
-               var warn, log, liveConfig, liveMessages,
+               var warn, error, log, liveConfig, liveMessages,
                        ajaxRequests = [];
 
                liveConfig = mw.config.values;
 
                function suppressWarnings() {
                        warn = mw.log.warn;
-                       mw.log.warn = $.noop;
+                       error = mw.log.error;
+                       mw.log.warn = mw.log.error = $.noop;
                }
 
                function restoreWarnings() {
+                       // Guard against calls not balanced with suppressWarnings()
                        if ( warn !== undefined ) {
                                mw.log.warn = warn;
-                               warn = undefined;
+                               mw.log.error = error;
+                               warn = error = undefined;
                        }
                }