2 * Implementation for mediaWiki.log stub
8 * Log output to the console.
10 * In the case that the browser does not have a console available, one is created by appending a
11 * <div> element to the bottom of the body and then appending a <div> element to that for each
14 * @author Michael Dale <mdale@wikimedia.org>
15 * @author Trevor Parscal <tparscal@wikimedia.org>
16 * @param {string} string Message to output to console
18 mw
.log = function( string
, prefix
) {
19 // Allow log messages to use a configured prefix
20 if ( typeof prefix
== 'string' ) {
21 string
= prefix
+ '> ' + string
;
22 } else if ( mw
.config
.exists( 'mw.log.prefix' ) ) {
23 string
= mw
.config
.get( 'mw.log.prefix' ) + '> ' + string
;
25 // Try to use an existing console
26 if ( typeof window
.console
!== 'undefined' && typeof window
.console
.log
== 'function' ) {
27 console
.log( string
);
31 var time
= ( d
.getHours() < 10 ? '0' + d
.getHours() : d
.getHours() ) +
32 ':' + ( d
.getMinutes() < 10 ? '0' + d
.getMinutes() : d
.getMinutes() ) +
33 ':' + ( d
.getSeconds() < 10 ? '0' + d
.getSeconds() : d
.getSeconds() ) +
34 '.' + ( d
.getMilliseconds() < 10 ? '00' + d
.getMilliseconds() : ( d
.getMilliseconds() < 100 ? '0' + d
.getMilliseconds() : d
.getMilliseconds() ) );
35 // Show a log box for console-less browsers
36 var $log
= $( '#mw-log-console' );
38 $log
= $( '<div id="mw-log-console"></div>' )
47 'background-color': 'white',
48 'border-top': 'solid 2px #ADADAD'
55 'border-bottom': 'solid 1px #DDDDDD',
57 'font-family': 'monospace',
58 'padding': '0.125em 0.25em'
61 .append( '<span style="float:right">[' + time
+ ']</span>' )