2 * Logger for MediaWiki javascript.
3 * Implements the stub left by the main 'mediawiki' module.
5 * @author Michael Dale <mdale@wikimedia.org>
6 * @author Trevor Parscal <tparscal@wikimedia.org>
12 * Logs a message to the console.
14 * In the case the browser does not have a console API, a console is created on-the-fly by appending
15 * a <div id="mw-log-console"> element to the bottom of the body and then appending this and future
16 * messages to that, instead of the console.
18 * @param {String} First in list of variadic messages to output to console.
20 mw.log = function( /* logmsg, logmsg, */ ) {
21 // Turn arguments into an array
22 var args = Array.prototype.slice.call( arguments ),
23 // Allow log messages to use a configured prefix to identify the source window (ie. frame)
24 prefix = mw.config.exists( 'mw.log.prefix' ) ? mw.config.get( 'mw.log.prefix' ) + '> ' : '';
26 // Try to use an existing console
27 if ( window.console !== undefined && $.isFunction( window.console.log ) ) {
28 args.unshift( prefix );
29 window.console.log.apply( window.console, args );
33 // If there is no console, use our own log box
34 mw.loader.using( 'jquery.footHovzer', function () {
37 // Create HH:MM:SS.MIL timestamp
38 time = ( d.getHours() < 10 ? '0' + d.getHours() : d.getHours() ) +
39 ':' + ( d.getMinutes() < 10 ? '0' + d.getMinutes() : d.getMinutes() ) +
40 ':' + ( d.getSeconds() < 10 ? '0' + d.getSeconds() : d.getSeconds() ) +
41 '.' + ( d.getMilliseconds() < 10 ? '00' + d.getMilliseconds() : ( d.getMilliseconds() < 100 ? '0' + d.getMilliseconds() : d.getMilliseconds() ) ),
42 $log = $( '#mw-log-console' );
45 $log = $( '<div id="mw-log-console"></div>' ).css( {
48 backgroundColor: 'white',
49 borderTop: 'solid 2px #ADADAD'
51 var hovzer = $.getFootHovzer();
52 hovzer.$.append( $log );
58 borderBottom: 'solid 1px #DDDDDD',
60 fontFamily: 'monospace',
61 whiteSpace: 'pre-wrap',
62 padding: '0.125em 0.25em'
64 .text( prefix + args.join( ', ' ) )
65 .prepend( '<span style="float: right;">[' + time + ']</span>' )