wiki.techinc.nl/includes/debug/logger/ConsoleLogger.php
Tim Starling a59ed5f3de Add ConsoleLogger, use it for eval.php -d
eval.php previously set $wgDebugLogFile to /dev/stdout. This had the
following problems:

* It doesn't work if the maintenance script is executed via sudo, since
  /dev/stdout is typically owned by the original user, so MW can't open
  it. Using php://stdout worked on HHVM but not PHP.
* Setting $wgDebugLogFile has no effect if the wiki uses MonologSpi.
* Setting $wgDebugLogFile has no effect on channels configured with
  $wgDebugLogGroups.
* stderr is a more appropriate place to send logging output.
* Writing to configuration variables is discouraged.

So, add ConsoleSpi, which is a very simple logging service provider
which sends all messages to stderr. This should be suitable for
debugging with eval.php or shell.php in WMF production or beta.

Change-Id: Ib0d6ce45e0cbecd58263fc4e360c63d4149acb3a
2017-04-28 10:05:05 +10:00

21 lines
517 B
PHP

<?php
namespace MediaWiki\Logger;
use Psr\Log\AbstractLogger;
/**
* A logger which writes to the terminal. The output is supposed to be
* human-readable, and should be changed as necessary to better achieve that
* goal.
*/
class ConsoleLogger extends AbstractLogger {
public function __construct( $channel ) {
$this->channel = $channel;
}
public function log( $level, $message, array $context = [] ) {
fwrite( STDERR, "[$level] " .
LegacyLogger::format( $this->channel, $message, $context ) );
}
}