Page MenuHomePhabricator

Implement feature for logging in debug mode
Closed, DeclinedPublic

Description

I find the total lack of mw.log usage surprising. I suspect the reason may be that it takes up space/bandwidth, which - given that it is a no-op in production mode - is understandable.

Enabling logging output in PHP gives one a useful trace of the general process from initialization to handling of the request, building response, etc..

But in JavaScript there is practically no logging output in debug mode. The only output to the console is from the local log() function in mediawiki.js in case of module errors.

Perhaps we can find a way to filter them out in production mode? (Either in minification or some post-processor.)

The parser in JavaScriptMinifier seems an attractive place to implement something like this (whether or not through a hook[1]).

[1] Not an MWHook, as it's a standalone library. But this may work:

JavaScriptMinifier::addHook('comments', array( $rl, 'enableJSDebugLogging') );

ResourceLoader {
  public function enableJSDebugLogging(
    $context, // array( file =>, line => )
    $block // '/* .. \n * @log mw.log("foo", x, y) \n **/'
  ) {
  /* Replace comment with function call in debug mode. */
}
}

Details

Reference
bz37763

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 22 2014, 12:25 AM
bzimport set Reference to bz37763.
bzimport added a subscriber: Unknown Object (MLST).
Krinkle lowered the priority of this task from Medium to Low.Jan 5 2015, 3:37 PM
Krinkle updated the task description. (Show Details)
Krinkle set Security to None.
Krinkle removed a subscriber: Unknown Object (MLST).

I filed this because it stood out when described from a slidedeck perspective, but day-to-day this has never come up in the past 10+ years. I suspect this is part because browsers have modern devtools built-in, and these can be applied on any web page, including in production. This means there's rarely a need to compromise away from proper debugging in favour of print statements.