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 // We don't need the dummy, but it has other methods on it
13 // that we need to restore afterwards.
14 var original = mw.log,
15 slice = Array.prototype.slice;
18 * Logs a message to the console in debug mode.
20 * In the case the browser does not have a console API, a console is created on-the-fly by appending
21 * a `<div id="mw-log-console">` element to the bottom of the body and then appending this and future
22 * messages to that, instead of the console.
25 * @param {string...} msg Messages to output to console.
27 mw.log = function () {
28 // Turn arguments into an array
29 var args = slice.call( arguments ),
30 // Allow log messages to use a configured prefix to identify the source window (ie. frame)
31 prefix = mw.config.exists( 'mw.log.prefix' ) ? mw.config.get( 'mw.log.prefix' ) + '> ' : '';
33 // Try to use an existing console
34 // Generally we can cache this, but in this case we want to re-evaluate this as a
35 // global property live so that things like Firebug Lite can take precedence.
36 if ( window.console && window.console.log && window.console.log.apply ) {
37 args.unshift( prefix );
38 window.console.log.apply( window.console, args );
42 // If there is no console, use our own log box
43 mw.loader.using( 'jquery.footHovzer', function () {
47 // Create HH:MM:SS.MIL timestamp
48 time = ( d.getHours() < 10 ? '0' + d.getHours() : d.getHours() ) +
49 ':' + ( d.getMinutes() < 10 ? '0' + d.getMinutes() : d.getMinutes() ) +
50 ':' + ( d.getSeconds() < 10 ? '0' + d.getSeconds() : d.getSeconds() ) +
51 '.' + ( d.getMilliseconds() < 10 ? '00' + d.getMilliseconds() : ( d.getMilliseconds() < 100 ? '0' + d.getMilliseconds() : d.getMilliseconds() ) ),
52 $log = $( '#mw-log-console' );
55 $log = $( '<div id="mw-log-console"></div>' ).css( {
58 backgroundColor: 'white',
59 borderTop: 'solid 2px #ADADAD'
61 hovzer = $.getFootHovzer();
62 hovzer.$.append( $log );
68 borderBottom: 'solid 1px #DDDDDD',
70 fontFamily: 'monospace',
71 whiteSpace: 'pre-wrap',
72 padding: '0.125em 0.25em'
74 .text( prefix + args.join( ', ' ) )
75 .prepend( '<span style="float: right;">[' + time + ']</span>' )
80 // Restore original methods
81 mw.log.warn = original.warn;
82 mw.log.deprecate = original.deprecate;
84 }( mediaWiki, jQuery ) );