9c3d89034a0ef12feae982bad7e265920d02f6d1
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 logmsg {String} Messages to output to the console.
20 mw
.log = function( logmsg
) {
21 // Allow log messages to use a configured prefix to identify the source window (ie. frame)
22 if ( mw
.config
.exists( 'mw.log.prefix' ) ) {
23 logmsg
= mw
.config
.get( 'mw.log.prefix' ) + '> ' + logmsg
;
26 // Try to use an existing console
27 if ( window
.console
!== undefined && $.isFunction( window
.console
.log
) ) {
28 window
.console
.log( logmsg
);
32 // If there is no console, use our own log box
35 // Create HH:MM:SS.MIL timestamp
36 time
= ( d
.getHours() < 10 ? '0' + d
.getHours() : d
.getHours() ) +
37 ':' + ( d
.getMinutes() < 10 ? '0' + d
.getMinutes() : d
.getMinutes() ) +
38 ':' + ( d
.getSeconds() < 10 ? '0' + d
.getSeconds() : d
.getSeconds() ) +
39 '.' + ( d
.getMilliseconds() < 10 ? '00' + d
.getMilliseconds() : ( d
.getMilliseconds() < 100 ? '0' + d
.getMilliseconds() : d
.getMilliseconds() ) ),
40 $log
= $( '#mw-log-console' );
43 $log
= $( '<div id="mw-log-console"></div>' ).css( {
51 backgroundColor
: 'white',
52 borderTop
: 'solid 2px #ADADAD'
55 // Since the position is fixed, make sure we don't hide any actual content.
56 // Increase padding to account for #mw-log-console.
57 .css( 'paddingBottom', '+=150px' )
63 borderBottom
: 'solid 1px #DDDDDD',
65 fontFamily
: 'monospace',
66 whiteSpace
: 'pre-wrap',
67 padding
: '0.125em 0.25em'
70 .prepend( '<span style="float: right;">[' + time
+ ']</span>' )