ConsoleLogger.php 620 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. namespace MediaWiki\Logger;
  3. use Psr\Log\AbstractLogger;
  4. /**
  5. * A logger which writes to the terminal. The output is supposed to be
  6. * human-readable, and should be changed as necessary to better achieve that
  7. * goal.
  8. */
  9. class ConsoleLogger extends AbstractLogger {
  10. /** @var string */
  11. private $channel;
  12. /**
  13. * @param string $channel
  14. */
  15. public function __construct( $channel ) {
  16. $this->channel = $channel;
  17. }
  18. /**
  19. * @inheritDoc
  20. */
  21. public function log( $level, $message, array $context = [] ) {
  22. fwrite( STDERR, "[$level] " .
  23. LegacyLogger::format( $this->channel, $message, $context ) );
  24. }
  25. }