Update to PSR-3 logging

Change-Id: I8b61cec606e75a3cf2143b1fa54e5dff2cfa3c7f
This commit is contained in:
physikerwelt 2015-03-16 17:43:20 -04:00 committed by BryanDavis
parent 81dbee82c9
commit 5e46586ada
7 changed files with 81 additions and 54 deletions

View File

@ -46,9 +46,9 @@ class MathHooks {
$confstr .= '!' . self::mathCacheKey . $mathOption;
}
wfDebugLog( 'Math', "New cache key: $confstr" );
MWLoggerFactory::getInstance( 'Math' )->debug( "New cache key: $confstr" );
} else {
wfDebugLog( 'Math', "Cache key found $confstr" );
MWLoggerFactory::getInstance( 'Math' )->debug( "Cache key found $confstr" );
}
}
@ -117,10 +117,11 @@ class MathHooks {
}
if ( $renderer->render() ) {
wfDebugLog( 'Math', "Rendering successful. Writing output" );
MWLoggerFactory::getInstance( 'Math' )->info( "Rendering successful. Writing output" );
$renderedMath = $renderer->getHtmlOutput();
} else {
wfDebugLog( 'Math', "Rendering failed. Printing error message." );
MWLoggerFactory::getInstance( 'Math' )->warning(
"Rendering failed. Printing error message." );
return $renderer->getLastError();
}
Hooks::run( 'MathFormulaPostRender',
@ -157,7 +158,9 @@ class MathHooks {
// If the default option is not in the valid options the
// user interface throws an exception (BUG 64844)
if ( ! in_array( $wgDefaultUserOptions['math'] , $wgMathValidModes ) ) {
wfDebugLog( 'Math', "Warning: Misconfiguration \$wgDefaultUserOptions['math'] is not in \$wgMathValidModes. Please check your LocalSetting.php file." );
MWLoggerFactory::getInstance( 'Math' )->critical( "Misconfiguration: \n" .
"\$wgDefaultUserOptions['math'] is not in \$wgMathValidModes. \n".
"Please check your LocalSetting.php file." );
// Display the checkbox in the first option.
$wgDefaultUserOptions['math'] = $wgMathValidModes[0];
}

View File

@ -62,7 +62,7 @@ class MathInputCheckTexvc extends MathInputCheck {
if ( !is_executable( $wgMathTexvcCheckExecutable ) ) {
$msg = 'Missing "texvccheck" executable. Please see math/README to configure.';
trigger_error( $msg, E_USER_NOTICE );
wfDebugLog( 'Math', $msg );
MWLoggerFactory::getInstance( 'Math' )->critical( $msg );
return true;
}
@ -73,12 +73,12 @@ class MathInputCheckTexvc extends MathInputCheck {
$cmd = 'sh -c ' . wfEscapeShellArg( $cmd );
}
wfDebugLog( 'Math', "TeX check command: $cmd\n" );
MWLoggerFactory::getInstance( 'Math' )->debug( "TeX check command: $cmd\n" );
$contents = wfShellExec( $cmd );
wfDebugLog( 'Math', "TeX check result:\n $contents\n---\n" );
MWLoggerFactory::getInstance( 'Math' )->debug( "TeX check result:\n $contents\n---\n" );
if ( strlen( $contents ) === 0 ) {
wfDebugLog( 'Math', "TeX check output was empty. \n" );
MWLoggerFactory::getInstance( 'Math' )->notice( "TeX check output was empty. \n" );
$this->lastError = $this->convertTexvcError( $contents );
return false;
@ -88,13 +88,14 @@ class MathInputCheckTexvc extends MathInputCheck {
if ( $retval !== '+' ) {
$this->lastError = $this->convertTexvcError( $contents );
wfDebugLog( 'Math', 'checkTex failed:' . $this->lastError );
MWLoggerFactory::getInstance( 'Math' )->notice( 'checkTex failed:' . $this->lastError );
return false;
} else {
$this->validTeX = substr( $contents, 1 );
$this->isValid = true;
wfDebugLog( 'Math', 'checkTex successful tex is now: ' . $this->validTeX );
MWLoggerFactory::getInstance( 'Math' )->debug(
'checkTex successful tex is now: ' . $this->validTeX );
return true;
}

View File

@ -84,7 +84,7 @@ class MathLaTeXML extends MathMathML {
$texcmd = rawurlencode( $tex );
$settings = $this->serializeSettings( $this->getLaTeXMLSettings() );
$postData = $settings . '&tex=' . $texcmd;
wfDebugLog( 'Math', 'Get post data: ' . $postData );
MWLoggerFactory::getInstance( 'Math' )->debug( 'Get post data: ' . $postData );
return $postData;
}
@ -96,7 +96,8 @@ class MathLaTeXML extends MathMathML {
global $wgMathDebug;
if ( trim( $this->getTex() ) === '' ) {
wfDebugLog( 'Math', "Rendering was requested, but no TeX string is specified." );
MWLoggerFactory::getInstance( 'Math' )->notice(
"Rendering was requested, but no TeX string is specified." );
$this->lastError = $this->getError( 'math_empty_tex' );
return false;
}
@ -124,7 +125,8 @@ class MathLaTeXML extends MathMathML {
// Do not print bad mathml. It's probably too verbose and might
// mess up the browser output.
$this->lastError = $this->getError( 'math_invalidxml', $this->getModeStr(), $host );
wfDebugLog( 'Math', "\nLaTeXML InvalidMathML:" . var_export( array(
MWLoggerFactory::getInstance( 'Math' )->notice(
"\nLaTeXML InvalidMathML:" . var_export( array(
'post' => $post,
'host' => $host,
'result' => $res
@ -133,7 +135,8 @@ class MathLaTeXML extends MathMathML {
}
} else {
$this->lastError = $this->getError( 'math_invalidjson', $this->getModeStr(), $host );
wfDebugLog( 'Math', "\nLaTeXML InvalidJSON:" . var_export( array(
MWLoggerFactory::getInstance( 'Math' )->notice(
"\nLaTeXML InvalidJSON:" . var_export( array(
'post' => $post,
'host' => $host,
'res' => $res
@ -188,7 +191,8 @@ class MathLaTeXML extends MathMathML {
$this->svg = $renderer->getSvg();
} else {
$lastError = $renderer->getLastError();
wfDebugLog( 'Math', 'failed to convert LaTeXML-MathML to SVG:' . $lastError );
MWLoggerFactory::getInstance( 'Math' )->error(
'failed to convert LaTeXML-MathML to SVG:' . $lastError );
}
return $res;
}

View File

@ -97,26 +97,26 @@ class MathMathML extends MathRenderer {
*/
private function renderingRequired() {
if ( $this->isPurge() ) {
wfDebugLog( 'Math', 'Rerendering was requested.' );
MWLoggerFactory::getInstance( 'Math' )->debug( 'Rerendering was requested.' );
return true;
} else {
$dbres = $this->isInDatabase();
if ( $dbres ) {
if ( $this->isValidMathML( $this->getMathml() ) ) {
wfDebugLog( 'Math', 'Valid MathML entry found in database.' );
MWLoggerFactory::getInstance( 'Math' )->debug( 'Valid MathML entry found in database.' );
if ( $this->getSvg( 'cached' ) ) {
wfDebugLog( 'Math', 'SVG-fallback found in database.' );
MWLoggerFactory::getInstance( 'Math' )->debug( 'SVG-fallback found in database.' );
return false;
} else {
wfDebugLog( 'Math', 'SVG-fallback missing.' );
MWLoggerFactory::getInstance( 'Math' )->debug( 'SVG-fallback missing.' );
return true;
}
} else {
wfDebugLog( 'Math', 'Malformatted entry found in database' );
MWLoggerFactory::getInstance( 'Math' )->debug( 'Malformatted entry found in database' );
return true;
}
} else {
wfDebugLog( 'Math', 'No entry found in database.' );
MWLoggerFactory::getInstance( 'Math' )->debug( 'No entry found in database.' );
return true;
}
}
@ -160,7 +160,7 @@ class MathMathML extends MathRenderer {
if ( $status->hasMessage( 'http-timed-out' ) ) {
$error = $this->getError( 'math_timeout', $this->getModeStr(), $host );
$res = false;
wfDebugLog( 'Math', "\nTimeout:" . var_export( array(
MWLoggerFactory::getInstance( 'Math' )->debug( "\nTimeout:" . var_export( array(
'post' => $post,
'host' => $host,
'timeout' => $wgMathLaTeXMLTimeout
@ -171,7 +171,7 @@ class MathMathML extends MathRenderer {
$error =
$this->getError( 'math_invalidresponse', $this->getModeStr(), $host, $errormsg,
$this->getModeStr( MW_MATH_MATHML ) );
wfDebugLog( 'Math', "\nNoResponse:" . var_export( array(
MWLoggerFactory::getInstance( 'Math' )->debug( "\nNoResponse:" . var_export( array(
'post' => $post,
'host' => $host,
'errormsg' => $errormsg
@ -194,7 +194,7 @@ class MathMathML extends MathRenderer {
} else {
$host = $this->hosts;
}
wfDebugLog( 'Math', 'picking host ' . $host );
MWLoggerFactory::getInstance( 'Math' )->debug( 'picking host ' . $host );
return $host;
}
@ -218,7 +218,7 @@ class MathMathML extends MathRenderer {
$out = 'type=tex&q=' . rawurlencode( $input );
}
}
wfDebugLog( 'Math', 'Get post data: ' . $out );
MWLoggerFactory::getInstance( 'Math' )->debug( 'Get post data: ' . $out );
return $out;
}
@ -228,7 +228,7 @@ class MathMathML extends MathRenderer {
*/
protected function doRender() {
if ( $this->getTex() === '' ) {
wfDebugLog( 'Math', 'Rendering was requested, but no TeX string is specified.' );
MWLoggerFactory::getInstance( 'Math' )->debug( 'Rendering was requested, but no TeX string is specified.' );
$this->lastError = $this->getError( 'math_empty_tex' );
return false;
}
@ -249,7 +249,8 @@ class MathMathML extends MathRenderer {
$log = wfMessage( 'math_unknown_error' )->inContentLanguage()->escaped();
}
$this->lastError = $this->getError( 'math_mathoid_error', $host, $log );
wfDebugLog( 'Math', 'Mathoid conversion error:' . var_export( array(
MWLoggerFactory::getInstance( 'Math' )->notice(
'Mathoid conversion error:' . var_export( array(
'post' => $post,
'host' => $host,
'result' => $res
@ -258,7 +259,8 @@ class MathMathML extends MathRenderer {
}
} else {
$this->lastError = $this->getError( 'math_invalidjson', $host );
wfDebugLog( 'Math', "\nMathML InvalidJSON:" . var_export( array(
MWLoggerFactory::getInstance( 'Math' )->error(
"\nMathML InvalidJSON:" . var_export( array(
'post' => $post,
'host' => $host,
'res' => $res
@ -285,7 +287,8 @@ class MathMathML extends MathRenderer {
$xmlObject = new XmlTypeCheck( $XML, null, false );
if ( !$xmlObject->wellFormed ) {
wfDebugLog( 'Math', "XML validation error:\n " . var_export( $XML, true ) . "\n" );
MWLoggerFactory::getInstance( 'Math' )->error(
"XML validation error:\n " . var_export( $XML, true ) . "\n" );
} else {
$name = $xmlObject->getRootElement();
$elementSplit = explode( ':', $name );
@ -297,7 +300,7 @@ class MathMathML extends MathRenderer {
if ( in_array( $localName , $this->getAllowedRootElements() ) ) {
$out = true;
} else {
wfDebugLog( 'Math', "got wrong root element : $name" );
MWLoggerFactory::getInstance( 'Math' )->error( "got wrong root element : $name" );
}
}
return $out;
@ -358,7 +361,8 @@ class MathMathML extends MathRenderer {
}
// TODO: move the common styles to the global stylesheet!
$style = 'background-image: url(\''. $url. '\'); background-repeat: no-repeat; background-size: 100% 100%;';
$style = 'background-image: url(\''. $url .
'\'); background-repeat: no-repeat; background-size: 100% 100%;';
$this->correctSvgStyle( $this->getSvg(), $style );
if ( $class ) { $attribs['class'] = $class; }
if ( $style ) { $attribs['style'] = $style; }
@ -468,7 +472,8 @@ class MathMathML extends MathRenderer {
$this->setSvg( $jsonResult->svg );
}
} else {
wfDebugLog( 'Math', 'Missing SVG property in JSON result.' );
MWLoggerFactory::getInstance( 'Math' )->error(
'Missing SVG property in JSON result.' );
}
if ( $wgMathDebug ) {
$this->setLog( $jsonResult->log );

View File

@ -172,7 +172,8 @@ abstract class MathRenderer {
default:
$renderer = new MathMathML( $tex, $params );
}
wfDebugLog( 'Math', 'start rendering $' . $renderer->tex . '$ in mode ' . $mode );
MWLoggerFactory::getInstance( 'Math' )->info( 'start rendering $' . $renderer->tex .
'$ in mode ' . $mode );
$renderer->setMathStyle( $mathStyle );
return $renderer;
}
@ -327,8 +328,8 @@ abstract class MathRenderer {
# Now save it back to the DB:
if ( !wfReadOnly() ) {
$dbw = $dbw ?: wfGetDB( DB_MASTER );
wfDebugLog( 'Math', 'store entry for $' . $this->tex . '$ in database (hash:' .
$this->getMd5() . ")\n" );
MWLoggerFactory::getInstance( 'Math' )->info( 'store entry for $' . $this->tex .
'$ in database (hash:' . $this->getMd5() . ")\n" );
$outArray = $this->dbOutArray();
$method = __METHOD__;
$mathTableName = $this->getMathTableName();
@ -339,8 +340,9 @@ abstract class MathRenderer {
) {
$dbw->update( $mathTableName, $outArray,
array( 'math_inputhash' => $inputHash ), $method );
wfDebugLog( 'Math', 'Row updated after db transaction was idle: ' .
var_export( $outArray, true ) . " to database \n" );
MWLoggerFactory::getInstance( 'Math' )->debug(
'Row updated after db transaction was idle: ' .
var_export( $outArray, true ) . " to database \n" );
} );
} else {
$dbw->onTransactionIdle( function () use (
@ -348,11 +350,13 @@ abstract class MathRenderer {
) {
$dbw->insert( $mathTableName, $outArray, $method, array( 'IGNORE' ) );
if ( $wgMathDebug ) {
wfDebugLog( 'Math', 'Row inserted after db transaction was idle ' .
var_export( $outArray, true ) . " to database \n" );
MWLoggerFactory::getInstance( 'Math' )->debug(
'Row inserted after db transaction was idle ' .
var_export( $outArray, true ) . " to database \n" );
if ( $dbw->affectedRows() == 0 ) {
// That's the price for the delayed update.
wfDebugLog( 'Math', 'Entry could not be written. Might be changed in between. ' );
MWLoggerFactory::getInstance( 'Math' )->notice(
'Entry could not be written. Might be changed in between. ' );
}
}
} );
@ -394,13 +398,13 @@ abstract class MathRenderer {
* Writes cache. Writes the database entry if values were changed
*/
public function writeCache() {
wfDebugLog( 'Math', "writing of cache requested." );
MWLoggerFactory::getInstance( 'Math' )->debug( "writing of cache requested." );
if ( $this->isChanged() ) {
wfDebugLog( 'Math', "Change detected. Perform writing." );
MWLoggerFactory::getInstance( 'Math' )->debug( "Change detected. Perform writing." );
$this->writeToDatabase();
return true;
} else {
wfDebugLog( 'Math', "Nothing was changed. Don't write to database." );
MWLoggerFactory::getInstance( 'Math' )->debug( "Nothing was changed. Don't write to database." );
return false;
}
}
@ -521,7 +525,7 @@ abstract class MathRenderer {
// until this issue is resolved we use ?mathpurge=true instead
$mathpurge = $request->getBool( 'mathpurge', false );
if ( $mathpurge ) {
wfDebugLog( 'Math', 'Re-Rendering on user request' );
MWLoggerFactory::getInstance( 'Math' )->debug( 'Re-Rendering on user request' );
return true;
} else {
return false;

View File

@ -43,7 +43,8 @@ class MathTexvc extends MathRenderer {
$out['math_html'] = $this->html;
$out['math_mathml'] = utf8_encode( $this->getMathml() );
$out['math_inputhash'] = $this->getInputHash();
wfDebugLog( 'Math', 'Store Hashpath of image' . bin2hex( $outmd5_sql ) );
MWLoggerFactory::getInstance( 'Math' )->info( 'Store Hashpath of image' .
bin2hex( $outmd5_sql ) );
return $out;
}
@ -64,7 +65,8 @@ class MathTexvc extends MathRenderer {
$xhash = unpack( 'H32md5',
$dbr->decodeBlob( $rpage->math_outputhash ) . " " );
$this->hash = $xhash['md5'];
wfDebugLog( 'Math', 'Hashpath of PNG-File:' . bin2hex( $this->hash ) );
MWLoggerFactory::getInstance( 'Math' )->info( 'Hashpath of PNG-File:' .
bin2hex( $this->hash ) );
$this->conservativeness = $rpage->math_html_conservativeness;
$this->html = $rpage->math_html;
return true;
@ -99,7 +101,8 @@ class MathTexvc extends MathRenderer {
public function getHashPath() {
$path = $this->getBackend()->getRootStoragePath() .
'/math-render/' . $this->getHashSubPath();
wfDebugLog( 'Math', "TeX: getHashPath, hash is: {$this->getHash()}, path is: $path\n" );
MWLoggerFactory::getInstance( 'Math' )->debug(
"TeX: getHashPath, hash is: {$this->getHash()}, path is: $path\n" );
return $path;
}
@ -175,7 +178,8 @@ class MathTexvc extends MathRenderer {
$tmpDir = wfTempDir();
if ( !is_executable( $wgTexvc ) ) {
wfDebugLog( 'Math', "$wgTexvc does not exist or is not executable." );
MWLoggerFactory::getInstance( 'Math' )->error(
"$wgTexvc does not exist or is not executable." );
return $this->getError( 'math_notexvc' );
}
@ -192,18 +196,20 @@ class MathTexvc extends MathRenderer {
# Invoke it within cygwin sh, because texvc expects sh features in its default shell
$cmd = 'sh -c ' . wfEscapeShellArg( $cmd );
}
wfDebugLog( 'Math', "TeX: $cmd\n" );
wfDebugLog( 'Math', "Executing '$cmd'." );
MWLoggerFactory::getInstance( 'Math' )->debug( "TeX: $cmd\n" );
MWLoggerFactory::getInstance( 'Math' )->debug( "Executing '$cmd'." );
$retval = null;
$contents = wfShellExec( $cmd, $retval );
wfDebugLog( 'Math', "TeX output:\n $contents\n---\n" );
MWLoggerFactory::getInstance( 'Math' )->debug( "TeX output:\n $contents\n---\n" );
if ( strlen( $contents ) == 0 ) {
if ( !file_exists( $tmpDir ) || !is_writable( $tmpDir ) ) {
wfDebugLog( 'Math', "TeX output directory $tmpDir is missing or not writable" );
MWLoggerFactory::getInstance( 'Math' )->error(
"TeX output directory $tmpDir is missing or not writable" );
return $this->getError( 'math_bad_tmpdir' );
} else {
wfDebugLog( 'Math', "TeX command '$cmd' returned no output and status code $retval." );
MWLoggerFactory::getInstance( 'Math' )->error(
"TeX command '$cmd' returned no output and status code $retval." );
return $this->getError( 'math_unknown_error' );
}
}

4
README
View File

@ -55,3 +55,7 @@ For testing your installation run
php tests/phpunit/phpunit.php extensions/Math/tests/
from your MediWiki home path.
== Logging ==
The math extension supports PSR-3 logging:
Configuration can be dona via
$wgDebugLogGroups['Math'] = array( 'level' => 'info', 'destination' => '/path/to/file.log' );