mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Math
synced 2024-09-23 18:29:39 +00:00
PSR-3 logging cleanup
* Limit levels to MediaWiki recommended debug, info, warning, error * Don't add trailing newlines * Capitalize messages Change-Id: I211357b1cc014d6bed1717f22e2bf8ebfc4f386f
This commit is contained in:
parent
5e46586ada
commit
23ff28d71d
|
@ -48,7 +48,7 @@ class MathHooks {
|
|||
|
||||
MWLoggerFactory::getInstance( 'Math' )->debug( "New cache key: $confstr" );
|
||||
} else {
|
||||
MWLoggerFactory::getInstance( 'Math' )->debug( "Cache key found $confstr" );
|
||||
MWLoggerFactory::getInstance( 'Math' )->debug( "Cache key found: $confstr" );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -158,8 +158,8 @@ 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 ) ) {
|
||||
MWLoggerFactory::getInstance( 'Math' )->critical( "Misconfiguration: \n" .
|
||||
"\$wgDefaultUserOptions['math'] is not in \$wgMathValidModes. \n".
|
||||
MWLoggerFactory::getInstance( 'Math' )->error( 'Misconfiguration: '.
|
||||
"\$wgDefaultUserOptions['math'] is not in \$wgMathValidModes.\n".
|
||||
"Please check your LocalSetting.php file." );
|
||||
// Display the checkbox in the first option.
|
||||
$wgDefaultUserOptions['math'] = $wgMathValidModes[0];
|
||||
|
|
|
@ -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 );
|
||||
MWLoggerFactory::getInstance( 'Math' )->critical( $msg );
|
||||
MWLoggerFactory::getInstance( 'Math' )->error( $msg );
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -73,12 +73,12 @@ class MathInputCheckTexvc extends MathInputCheck {
|
|||
$cmd = 'sh -c ' . wfEscapeShellArg( $cmd );
|
||||
}
|
||||
|
||||
MWLoggerFactory::getInstance( 'Math' )->debug( "TeX check command: $cmd\n" );
|
||||
MWLoggerFactory::getInstance( 'Math' )->debug( "TeX check command: $cmd" );
|
||||
$contents = wfShellExec( $cmd );
|
||||
MWLoggerFactory::getInstance( 'Math' )->debug( "TeX check result:\n $contents\n---\n" );
|
||||
MWLoggerFactory::getInstance( 'Math' )->debug( "TeX check result: $contents\n---" );
|
||||
|
||||
if ( strlen( $contents ) === 0 ) {
|
||||
MWLoggerFactory::getInstance( 'Math' )->notice( "TeX check output was empty. \n" );
|
||||
MWLoggerFactory::getInstance( 'Math' )->warning( 'TeX check output was empty.' );
|
||||
$this->lastError = $this->convertTexvcError( $contents );
|
||||
|
||||
return false;
|
||||
|
@ -88,7 +88,7 @@ class MathInputCheckTexvc extends MathInputCheck {
|
|||
|
||||
if ( $retval !== '+' ) {
|
||||
$this->lastError = $this->convertTexvcError( $contents );
|
||||
MWLoggerFactory::getInstance( 'Math' )->notice( 'checkTex failed:' . $this->lastError );
|
||||
MWLoggerFactory::getInstance( 'Math' )->warning( 'checkTex failed: ' . $this->lastError );
|
||||
|
||||
return false;
|
||||
} else {
|
||||
|
|
|
@ -96,8 +96,8 @@ class MathLaTeXML extends MathMathML {
|
|||
global $wgMathDebug;
|
||||
|
||||
if ( trim( $this->getTex() ) === '' ) {
|
||||
MWLoggerFactory::getInstance( 'Math' )->notice(
|
||||
"Rendering was requested, but no TeX string is specified." );
|
||||
MWLoggerFactory::getInstance( 'Math' )->warning(
|
||||
'Rendering was requested, but no TeX string is specified.' );
|
||||
$this->lastError = $this->getError( 'math_empty_tex' );
|
||||
return false;
|
||||
}
|
||||
|
@ -125,22 +125,22 @@ 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 );
|
||||
MWLoggerFactory::getInstance( 'Math' )->notice(
|
||||
"\nLaTeXML InvalidMathML:" . var_export( array(
|
||||
MWLoggerFactory::getInstance( 'Math' )->warning(
|
||||
'LaTeXML InvalidMathML: ' . var_export( array(
|
||||
'post' => $post,
|
||||
'host' => $host,
|
||||
'result' => $res
|
||||
), true ) . "\n\n" );
|
||||
), true ) );
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
$this->lastError = $this->getError( 'math_invalidjson', $this->getModeStr(), $host );
|
||||
MWLoggerFactory::getInstance( 'Math' )->notice(
|
||||
"\nLaTeXML InvalidJSON:" . var_export( array(
|
||||
MWLoggerFactory::getInstance( 'Math' )->warning(
|
||||
'LaTeXML InvalidJSON:' . var_export( array(
|
||||
'post' => $post,
|
||||
'host' => $host,
|
||||
'res' => $res
|
||||
), true ) . "\n\n" );
|
||||
), true ) );
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
|
@ -192,7 +192,7 @@ class MathLaTeXML extends MathMathML {
|
|||
} else {
|
||||
$lastError = $renderer->getLastError();
|
||||
MWLoggerFactory::getInstance( 'Math' )->error(
|
||||
'failed to convert LaTeXML-MathML to SVG:' . $lastError );
|
||||
'Failed to convert LaTeXML-MathML to SVG:' . $lastError );
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
|
|
@ -96,27 +96,28 @@ class MathMathML extends MathRenderer {
|
|||
* @return boolean
|
||||
*/
|
||||
private function renderingRequired() {
|
||||
$logger = MWLoggerFactory::getInstance( 'Math' );
|
||||
if ( $this->isPurge() ) {
|
||||
MWLoggerFactory::getInstance( 'Math' )->debug( 'Rerendering was requested.' );
|
||||
$logger->debug( 'Rerendering was requested.' );
|
||||
return true;
|
||||
} else {
|
||||
$dbres = $this->isInDatabase();
|
||||
if ( $dbres ) {
|
||||
if ( $this->isValidMathML( $this->getMathml() ) ) {
|
||||
MWLoggerFactory::getInstance( 'Math' )->debug( 'Valid MathML entry found in database.' );
|
||||
$logger->debug( 'Valid MathML entry found in database.' );
|
||||
if ( $this->getSvg( 'cached' ) ) {
|
||||
MWLoggerFactory::getInstance( 'Math' )->debug( 'SVG-fallback found in database.' );
|
||||
$logger->debug( 'SVG-fallback found in database.' );
|
||||
return false;
|
||||
} else {
|
||||
MWLoggerFactory::getInstance( 'Math' )->debug( 'SVG-fallback missing.' );
|
||||
$logger->debug( 'SVG-fallback missing.' );
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
MWLoggerFactory::getInstance( 'Math' )->debug( 'Malformatted entry found in database' );
|
||||
$logger->debug( 'Malformatted entry found in database' );
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
MWLoggerFactory::getInstance( 'Math' )->debug( 'No entry found in database.' );
|
||||
$logger->debug( 'No entry found in database.' );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -160,22 +161,22 @@ class MathMathML extends MathRenderer {
|
|||
if ( $status->hasMessage( 'http-timed-out' ) ) {
|
||||
$error = $this->getError( 'math_timeout', $this->getModeStr(), $host );
|
||||
$res = false;
|
||||
MWLoggerFactory::getInstance( 'Math' )->debug( "\nTimeout:" . var_export( array(
|
||||
MWLoggerFactory::getInstance( 'Math' )->warning( 'Timeout:' . var_export( array(
|
||||
'post' => $post,
|
||||
'host' => $host,
|
||||
'timeout' => $wgMathLaTeXMLTimeout
|
||||
), true ) . "\n\n" );
|
||||
), true ) );
|
||||
} else {
|
||||
// for any other unkonwn http error
|
||||
$errormsg = $status->getHtml();
|
||||
$error =
|
||||
$this->getError( 'math_invalidresponse', $this->getModeStr(), $host, $errormsg,
|
||||
$this->getModeStr( MW_MATH_MATHML ) );
|
||||
MWLoggerFactory::getInstance( 'Math' )->debug( "\nNoResponse:" . var_export( array(
|
||||
MWLoggerFactory::getInstance( 'Math' )->warning( 'NoResponse:' . var_export( array(
|
||||
'post' => $post,
|
||||
'host' => $host,
|
||||
'errormsg' => $errormsg
|
||||
), true ) . "\n\n" );
|
||||
), true ) );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -194,7 +195,7 @@ class MathMathML extends MathRenderer {
|
|||
} else {
|
||||
$host = $this->hosts;
|
||||
}
|
||||
MWLoggerFactory::getInstance( 'Math' )->debug( 'picking host ' . $host );
|
||||
MWLoggerFactory::getInstance( 'Math' )->debug( 'Picking host ' . $host );
|
||||
return $host;
|
||||
}
|
||||
|
||||
|
@ -249,22 +250,22 @@ class MathMathML extends MathRenderer {
|
|||
$log = wfMessage( 'math_unknown_error' )->inContentLanguage()->escaped();
|
||||
}
|
||||
$this->lastError = $this->getError( 'math_mathoid_error', $host, $log );
|
||||
MWLoggerFactory::getInstance( 'Math' )->notice(
|
||||
MWLoggerFactory::getInstance( 'Math' )->warning(
|
||||
'Mathoid conversion error:' . var_export( array(
|
||||
'post' => $post,
|
||||
'host' => $host,
|
||||
'result' => $res
|
||||
), true ) . "\n\n" );
|
||||
), true ) );
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
$this->lastError = $this->getError( 'math_invalidjson', $host );
|
||||
MWLoggerFactory::getInstance( 'Math' )->error(
|
||||
"\nMathML InvalidJSON:" . var_export( array(
|
||||
'MathML InvalidJSON:' . var_export( array(
|
||||
'post' => $post,
|
||||
'host' => $host,
|
||||
'res' => $res
|
||||
), true ) . "\n\n" );
|
||||
), true ) );
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
|
@ -288,7 +289,7 @@ class MathMathML extends MathRenderer {
|
|||
$xmlObject = new XmlTypeCheck( $XML, null, false );
|
||||
if ( !$xmlObject->wellFormed ) {
|
||||
MWLoggerFactory::getInstance( 'Math' )->error(
|
||||
"XML validation error:\n " . var_export( $XML, true ) . "\n" );
|
||||
'XML validation error: ' . var_export( $XML, true ) );
|
||||
} else {
|
||||
$name = $xmlObject->getRootElement();
|
||||
$elementSplit = explode( ':', $name );
|
||||
|
@ -300,7 +301,7 @@ class MathMathML extends MathRenderer {
|
|||
if ( in_array( $localName , $this->getAllowedRootElements() ) ) {
|
||||
$out = true;
|
||||
} else {
|
||||
MWLoggerFactory::getInstance( 'Math' )->error( "got wrong root element : $name" );
|
||||
MWLoggerFactory::getInstance( 'Math' )->error( "Got wrong root element : $name" );
|
||||
}
|
||||
}
|
||||
return $out;
|
||||
|
|
|
@ -172,7 +172,7 @@ abstract class MathRenderer {
|
|||
default:
|
||||
$renderer = new MathMathML( $tex, $params );
|
||||
}
|
||||
MWLoggerFactory::getInstance( 'Math' )->info( 'start rendering $' . $renderer->tex .
|
||||
MWLoggerFactory::getInstance( 'Math' )->info( 'Start rendering $' . $renderer->tex .
|
||||
'$ in mode ' . $mode );
|
||||
$renderer->setMathStyle( $mathStyle );
|
||||
return $renderer;
|
||||
|
@ -328,21 +328,21 @@ abstract class MathRenderer {
|
|||
# Now save it back to the DB:
|
||||
if ( !wfReadOnly() ) {
|
||||
$dbw = $dbw ?: wfGetDB( DB_MASTER );
|
||||
MWLoggerFactory::getInstance( 'Math' )->info( '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() . ')' );
|
||||
$outArray = $this->dbOutArray();
|
||||
$method = __METHOD__;
|
||||
$mathTableName = $this->getMathTableName();
|
||||
if ( $this->isInDatabase() ) {
|
||||
$inputHash = $this->getInputHash();
|
||||
$dbw->onTransactionIdle( function () use (
|
||||
$dbw, $outArray, $inputHash, $method, $mathTableName
|
||||
$dbw, $outArray, $inputHash, $method, $mathTableName
|
||||
) {
|
||||
$dbw->update( $mathTableName, $outArray,
|
||||
array( 'math_inputhash' => $inputHash ), $method );
|
||||
MWLoggerFactory::getInstance( 'Math' )->debug(
|
||||
'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" );
|
||||
} );
|
||||
} else {
|
||||
$dbw->onTransactionIdle( function () use (
|
||||
|
@ -352,11 +352,11 @@ abstract class MathRenderer {
|
|||
if ( $wgMathDebug ) {
|
||||
MWLoggerFactory::getInstance( 'Math' )->debug(
|
||||
'Row inserted after db transaction was idle ' .
|
||||
var_export( $outArray, true ) . " to database \n" );
|
||||
var_export( $outArray, true ) . " to database" );
|
||||
if ( $dbw->affectedRows() == 0 ) {
|
||||
// That's the price for the delayed update.
|
||||
MWLoggerFactory::getInstance( 'Math' )->notice(
|
||||
'Entry could not be written. Might be changed in between. ' );
|
||||
MWLoggerFactory::getInstance( 'Math' )->warning(
|
||||
'Entry could not be written. Might be changed in between.' );
|
||||
}
|
||||
}
|
||||
} );
|
||||
|
@ -398,13 +398,14 @@ abstract class MathRenderer {
|
|||
* Writes cache. Writes the database entry if values were changed
|
||||
*/
|
||||
public function writeCache() {
|
||||
MWLoggerFactory::getInstance( 'Math' )->debug( "writing of cache requested." );
|
||||
$logger = MWLoggerFactory::getInstance( 'Math' );
|
||||
$logger->debug( 'Writing of cache requested.' );
|
||||
if ( $this->isChanged() ) {
|
||||
MWLoggerFactory::getInstance( 'Math' )->debug( "Change detected. Perform writing." );
|
||||
$logger->debug( 'Change detected. Perform writing.' );
|
||||
$this->writeToDatabase();
|
||||
return true;
|
||||
} else {
|
||||
MWLoggerFactory::getInstance( 'Math' )->debug( "Nothing was changed. Don't write to database." );
|
||||
$logger->debug( "Nothing was changed. Don't write to database." );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -102,7 +102,7 @@ class MathTexvc extends MathRenderer {
|
|||
$path = $this->getBackend()->getRootStoragePath() .
|
||||
'/math-render/' . $this->getHashSubPath();
|
||||
MWLoggerFactory::getInstance( 'Math' )->debug(
|
||||
"TeX: getHashPath, hash is: {$this->getHash()}, path is: $path\n" );
|
||||
"TeX: getHashPath, hash is: {$this->getHash()}, path is: $path" );
|
||||
return $path;
|
||||
}
|
||||
|
||||
|
@ -196,11 +196,11 @@ class MathTexvc extends MathRenderer {
|
|||
# Invoke it within cygwin sh, because texvc expects sh features in its default shell
|
||||
$cmd = 'sh -c ' . wfEscapeShellArg( $cmd );
|
||||
}
|
||||
MWLoggerFactory::getInstance( 'Math' )->debug( "TeX: $cmd\n" );
|
||||
MWLoggerFactory::getInstance( 'Math' )->debug( "TeX: $cmd" );
|
||||
MWLoggerFactory::getInstance( 'Math' )->debug( "Executing '$cmd'." );
|
||||
$retval = null;
|
||||
$contents = wfShellExec( $cmd, $retval );
|
||||
MWLoggerFactory::getInstance( 'Math' )->debug( "TeX output:\n $contents\n---\n" );
|
||||
MWLoggerFactory::getInstance( 'Math' )->debug( "TeX output:\n $contents\n---" );
|
||||
|
||||
if ( strlen( $contents ) == 0 ) {
|
||||
if ( !file_exists( $tmpDir ) || !is_writable( $tmpDir ) ) {
|
||||
|
|
Loading…
Reference in a new issue