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 () {
38 // Create HH:MM:SS.MIL timestamp
39 time = ( d.getHours() < 10 ? '0' + d.getHours() : d.getHours() ) +
40 ':' + ( d.getMinutes() < 10 ? '0' + d.getMinutes() : d.getMinutes() ) +
41 ':' + ( d.getSeconds() < 10 ? '0' + d.getSeconds() : d.getSeconds() ) +
42 '.' + ( d.getMilliseconds() < 10 ? '00' + d.getMilliseconds() : ( d.getMilliseconds() < 100 ? '0' + d.getMilliseconds() : d.getMilliseconds() ) ),
43 $log = $( '#mw-log-console' );
46 $log = $( '<div id="mw-log-console"></div>' ).css( {
49 backgroundColor: 'white',
50 borderTop: 'solid 2px #ADADAD'
52 hovzer = $.getFootHovzer();
53 hovzer.$.append( $log );
59 borderBottom: 'solid 1px #DDDDDD',
61 fontFamily: 'monospace',
62 whiteSpace: 'pre-wrap',
63 padding: '0.125em 0.25em'
65 .text( prefix + args.join( ', ' ) )
66 .prepend( '<span style="float: right;">[' + time + ']</span>' )
71 }( mediaWiki, jQuery ) );