AbstractProcessingHandler.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /*
  3. * This file is part of the Monolog package.
  4. *
  5. * (c) Jordi Boggiano <j.boggiano@seld.be>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Monolog\Handler;
  11. use Monolog\Logger;
  12. use Monolog\Formatter\FormatterInterface;
  13. use Monolog\Formatter\LineFormatter;
  14. /**
  15. * Base Handler class providing the Handler structure
  16. *
  17. * Classes extending it should (in most cases) only implement write($record)
  18. *
  19. * @author Jordi Boggiano <j.boggiano@seld.be>
  20. * @author Christophe Coevoet <stof@notk.org>
  21. */
  22. abstract class AbstractProcessingHandler extends AbstractHandler
  23. {
  24. /**
  25. * {@inheritdoc}
  26. */
  27. public function handle(array $record)
  28. {
  29. if ($record['level'] < $this->level) {
  30. return false;
  31. }
  32. $record = $this->processRecord($record);
  33. $record['formatted'] = $this->getFormatter()->format($record);
  34. $this->write($record);
  35. return false === $this->bubble;
  36. }
  37. /**
  38. * Writes the record down to the log of the implementing handler
  39. *
  40. * @param array $record
  41. * @return void
  42. */
  43. abstract protected function write(array $record);
  44. /**
  45. * Processes a record.
  46. *
  47. * @param array $record
  48. * @return array
  49. */
  50. protected function processRecord(array $record)
  51. {
  52. if ($this->processors) {
  53. foreach ($this->processors as $processor) {
  54. $record = call_user_func($processor, $record);
  55. }
  56. }
  57. return $record;
  58. }
  59. }