* Following id-naming, underscore to dash
[lhc/web/wiklou.git] / resources / mediawiki / mediawiki.log.js
index 52cbe48..871a457 100644 (file)
@@ -1,37 +1,39 @@
 /*
- * Debug output logging
+ * Implementation for mediaWiki.log stub
  */
 
-( function( $, mw ) {
+(function ($, mw) {
 
-/* Extension */
-
-$.extend( mw, {
-       
-       /* Functions */
-       
        /**
-        * Log output to the console
+        * Log output to the console.
         * 
-        * In the case that the browser does not have a console available, one is created by appending a <div> element to
-        * the bottom of the body and then appending a <div> element to that for each message.
+        * In the case that the browser does not have a console available, one is created by appending a
+        * <div> element to the bottom of the body and then appending a <div> element to that for each
+        * message.
         *
-        * @author Michael Dale <mdale@wikimedia.org>, Trevor Parscal <tparscal@wikimedia.org>
-        * @param {string} string message to output to console
+        * @author Michael Dale <mdale@wikimedia.org>
+        * @author Trevor Parscal <tparscal@wikimedia.org>
+        * @param {string} string Message to output to console
         */
-       'log': function( string ) {
+       mediaWiki.log = function( string ) {
                // Allow log messages to use a configured prefix                
                if ( mw.config.exists( 'mw.log.prefix' ) ) {
-                       string = mw.config.get( 'mw.log.prefix' ) + string;             
+                       string = mw.config.get( 'mw.log.prefix' ) + '> ' + string;              
                }
                // Try to use an existing console
-               if ( typeof window.console !== 'undefined' && typeof window.console.log == 'function' ) {
+               if ( typeof window.console !== 'undefined' && typeof window.console.log !== 'function' ) {
                        window.console.log( string );
                } else {
+                       // Set timestamp
+                       var d = new Date();
+                       var time = ( d.getHours() < 10 ? '0' + d.getHours() : d.getHours() ) +
+                                ':' + ( d.getMinutes() < 10 ? '0' + d.getMinutes() : d.getMinutes() ) +
+                                ':' + ( d.getSeconds() < 10 ? '0' + d.getSeconds() : d.getSeconds() ) +
+                                '.' + ( d.getMilliseconds() < 100 ? '0' + d.getMilliseconds() : d.getMilliseconds() );
                        // Show a log box for console-less browsers
-                       var $log = $( '#mw_log_console' );
+                       var $log = $( '#mw-log-console' );
                        if ( !$log.length ) {
-                               $log = $( '<div id="mw_log_console"></div>' )
+                               $log = $( '<div id="mw-log-console"></div>' )
                                        .css( {
                                                'position': 'absolute',
                                                'overflow': 'auto',
@@ -41,22 +43,22 @@ $.extend( mw, {
                                                'right': '0px',
                                                'height': '150px',
                                                'background-color': 'white',
-                                               'border-top': 'solid 1px #DDDDDD'
+                                               'border-top': 'solid 2px #ADADAD'
                                        } )
-                                       .appendTo( $( 'body' ) );
+                                       .appendTo( 'body' );
                        }
                        $log.append(
                                $( '<div></div>' )
-                                       .text( string )
                                        .css( {
                                                'border-bottom': 'solid 1px #DDDDDD',
                                                'font-size': 'small',
                                                'font-family': 'monospace',
                                                'padding': '0.125em 0.25em'
                                        } )
+                                       .text( string )
+                                       .append( '<span style="float:right">[' + time + ']</span>' )
                        );
                }
-       }
-} );
+       };
 
-} )( jQuery, mediaWiki );
\ No newline at end of file
+})(jQuery, mediaWiki);