DrushLog.php

  1. 8.0.x lib/Drush/Log/DrushLog.php
  2. 7.x lib/Drush/Log/DrushLog.php
  3. master lib/Drush/Log/DrushLog.php

Contains \Drush\Log\DrushLog.

This class is only used to convert logging calls made inside of Drupal into a logging format that is usable by Drush. This code is ONLY usable within the context of a bootstrapped Drupal 8 site.

See Drush\Log\Logger for our actuall LoggerInterface implementation, that does the work of logging messages that originate from Drush.

Namespace

Drush\Log

Classes

Namesort descending Description
DrushLog Redirects Drupal logging messages to Drush log.

File

lib/Drush/Log/DrushLog.php
View source
  1. <?php
  2. /**
  3. * @file
  4. * Contains \Drush\Log\DrushLog.
  5. *
  6. * This class is only used to convert logging calls made
  7. * inside of Drupal into a logging format that is usable
  8. * by Drush. This code is ONLY usable within the context
  9. * of a bootstrapped Drupal 8 site.
  10. *
  11. * See Drush\Log\Logger for our actuall LoggerInterface
  12. * implementation, that does the work of logging messages
  13. * that originate from Drush.
  14. */
  15. namespace Drush\Log;
  16. use Psr\Log\LoggerInterface;
  17. use Psr\Log\LogLevel;
  18. use Psr\Log\LoggerTrait;
  19. /**
  20. * Redirects Drupal logging messages to Drush log.
  21. *
  22. * Note that Drupal extends the LoggerInterface, and
  23. * needlessly replaces Psr\Log\LogLevels with Drupal\Core\Logger\RfcLogLevel.
  24. * Doing this arguably violates the Psr\Log contract,
  25. * but we can't help that here -- we just need to convert back.
  26. */
  27. class DrushLog implements LoggerInterface {
  28. use LoggerTrait;
  29. /**
  30. * {@inheritdoc}
  31. */
  32. public function log($level, $message, array $context = array()) {
  33. // Translate the RFC logging levels into their Drush counterparts, more or
  34. // less.
  35. // @todo ALERT, CRITICAL and EMERGENCY are considered show-stopping errors,
  36. // and they should cause Drush to exit or panic. Not sure how to handle this,
  37. // though.
  38. switch ($level) {
  39. case LogLevel::ALERT:
  40. case LogLevel::CRITICAL:
  41. case LogLevel::EMERGENCY:
  42. case LogLevel::ERROR:
  43. $error_type = 'error';
  44. break;
  45. case LogLevel::WARNING:
  46. $error_type = 'warning';
  47. break;
  48. case LogLevel::DEBUG:
  49. case LogLevel::INFO:
  50. case LogLevel::NOTICE:
  51. $error_type = 'notice';
  52. break;
  53. // TODO: Unknown log levels that are not defined
  54. // in Psr\Log\LogLevel SHOULD NOT be used. See
  55. // https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md
  56. // We should convert these to 'notice'.
  57. default:
  58. $error_type = $level;
  59. break;
  60. }
  61. drush_log($message, $error_type);
  62. }
  63. }