WhatFailureGroupHandler.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. /**
  12. * Forwards records to multiple handlers suppressing failures of each handler
  13. * and continuing through to give every handler a chance to succeed.
  14. *
  15. * @author Craig D'Amelio <craig@damelio.ca>
  16. */
  17. class WhatFailureGroupHandler extends GroupHandler
  18. {
  19. /**
  20. * {@inheritdoc}
  21. */
  22. public function handle(array $record)
  23. {
  24. if ($this->processors) {
  25. foreach ($this->processors as $processor) {
  26. $record = call_user_func($processor, $record);
  27. }
  28. }
  29. foreach ($this->handlers as $handler) {
  30. try {
  31. $handler->handle($record);
  32. } catch (\Exception $e) {
  33. // What failure?
  34. } catch (\Throwable $e) {
  35. // What failure?
  36. }
  37. }
  38. return false === $this->bubble;
  39. }
  40. /**
  41. * {@inheritdoc}
  42. */
  43. public function handleBatch(array $records)
  44. {
  45. if ($this->processors) {
  46. $processed = array();
  47. foreach ($records as $record) {
  48. foreach ($this->processors as $processor) {
  49. $processed[] = call_user_func($processor, $record);
  50. }
  51. }
  52. $records = $processed;
  53. }
  54. foreach ($this->handlers as $handler) {
  55. try {
  56. $handler->handleBatch($records);
  57. } catch (\Exception $e) {
  58. // What failure?
  59. } catch (\Throwable $e) {
  60. // What failure?
  61. }
  62. }
  63. }
  64. }