From 51054551b5e3b6e1eb388cefaba16674133dde44 Mon Sep 17 00:00:00 2001 From: Krinkle Date: Sat, 10 Sep 2011 22:29:57 +0000 Subject: [PATCH] mediawiki.log.js: Add support for variadic arguments (just like the native console does) * Use unshift() when calling window.console.log (that way logging an object will not result in "prefix> [object Object]" but in "prefix> { key: .., .. }" (which most consoles do, similar thing for logging elements for which most console API implementations offer special features) * Use string concatenation when using our own fabricated log. Did not use unshift for both, because in the latter that would show a bad comma ("prefix:>, foo, bar"). The native API does not show a comma between two logged variables, they're just shown next to each other. --- resources/mediawiki/mediawiki.log.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/resources/mediawiki/mediawiki.log.js b/resources/mediawiki/mediawiki.log.js index 9c3d89034a..6dff8fc4f1 100644 --- a/resources/mediawiki/mediawiki.log.js +++ b/resources/mediawiki/mediawiki.log.js @@ -15,17 +15,18 @@ * a
element to the bottom of the body and then appending this and future * messages to that, instead of the console. * - * @param logmsg {String} Messages to output to the console. + * @param {String} First in list of variadic messages to output to console. */ - mw.log = function( logmsg ) { - // Allow log messages to use a configured prefix to identify the source window (ie. frame) - if ( mw.config.exists( 'mw.log.prefix' ) ) { - logmsg = mw.config.get( 'mw.log.prefix' ) + '> ' + logmsg; - } + mw.log = function( /* logmsg, logmsg, */ ) { + // Turn arguments into an array + var args = Array.prototype.slice.call( arguments ), + // Allow log messages to use a configured prefix to identify the source window (ie. frame) + prefix = mw.config.exists( 'mw.log.prefix' ) ? mw.config.get( 'mw.log.prefix' ) + '> ' : ''; // Try to use an existing console if ( window.console !== undefined && $.isFunction( window.console.log ) ) { - window.console.log( logmsg ); + args.unshift( prefix ); + window.console.log.apply( window.console, args ); return; } @@ -66,7 +67,7 @@ whiteSpace: 'pre-wrap', padding: '0.125em 0.25em' } ) - .text( logmsg ) + .text( prefix + args.join( ', ' ) ) .prepend( '[' + time + ']' ) ); }; -- 2.20.1