/vendor/monolog/src/Monolog/Handler/AbstractHandler.php

https://github.com/nguyennamtien/TaskBoxx · PHP · 165 lines · 73 code · 20 blank · 72 comment · 1 complexity · 10da67e15a9c9396ff055cb61a701e06 MD5 · raw file

  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. */
  21. abstract class AbstractHandler implements HandlerInterface
  22. {
  23. protected $level = Logger::DEBUG;
  24. protected $bubble = false;
  25. /**
  26. * @var FormatterInterface
  27. */
  28. protected $formatter;
  29. protected $processors = array();
  30. /**
  31. * @param integer $level The minimum logging level at which this handler will be triggered
  32. * @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not
  33. */
  34. public function __construct($level = Logger::DEBUG, $bubble = false)
  35. {
  36. $this->level = $level;
  37. $this->bubble = $bubble;
  38. }
  39. /**
  40. * {@inheritdoc}
  41. */
  42. public function isHandling(array $record)
  43. {
  44. return $record['level'] >= $this->level;
  45. }
  46. /**
  47. * {@inheritdoc}
  48. */
  49. public function handleBatch(array $records)
  50. {
  51. foreach ($records as $record) {
  52. $this->handle($record);
  53. }
  54. }
  55. /**
  56. * Closes the handler.
  57. *
  58. * This will be called automatically when the object is destroyed
  59. */
  60. public function close()
  61. {
  62. }
  63. /**
  64. * {@inheritdoc}
  65. */
  66. public function pushProcessor($callback)
  67. {
  68. array_unshift($this->processors, $callback);
  69. }
  70. /**
  71. * {@inheritdoc}
  72. */
  73. public function popProcessor()
  74. {
  75. return array_shift($this->processors);
  76. }
  77. /**
  78. * {@inheritdoc}
  79. */
  80. public function setFormatter(FormatterInterface $formatter)
  81. {
  82. $this->formatter = $formatter;
  83. }
  84. /**
  85. * {@inheritdoc}
  86. */
  87. public function getFormatter()
  88. {
  89. if (!$this->formatter) {
  90. $this->formatter = $this->getDefaultFormatter();
  91. }
  92. return $this->formatter;
  93. }
  94. /**
  95. * Sets minimum logging level at which this handler will be triggered.
  96. *
  97. * @param integer $level
  98. */
  99. public function setLevel($level)
  100. {
  101. $this->level = $level;
  102. }
  103. /**
  104. * Gets minimum logging level at which this handler will be triggered.
  105. *
  106. * @return integer
  107. */
  108. public function getLevel()
  109. {
  110. return $this->level;
  111. }
  112. /**
  113. * Sets the bubbling behavior.
  114. *
  115. * @param Boolean $bubble True means that bubbling is not permitted.
  116. * False means that this handler allows bubbling.
  117. */
  118. public function setBubble($bubble)
  119. {
  120. $this->bubble = $bubble;
  121. }
  122. /**
  123. * Gets the bubbling behavior.
  124. *
  125. * @return Boolean True means that bubbling is not permitted.
  126. * False means that this handler allows bubbling.
  127. */
  128. public function getBubble()
  129. {
  130. return $this->bubble;
  131. }
  132. public function __destruct()
  133. {
  134. $this->close();
  135. }
  136. /**
  137. * Gets the default formatter.
  138. *
  139. * @return FormatterInterface
  140. */
  141. protected function getDefaultFormatter()
  142. {
  143. return new LineFormatter();
  144. }
  145. }