X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/mediawiki.git/blobdiff_plain/19e297c21b10b1b8a3acad5e73fc71dcb35db44a..6932310fd58ebef145fa01eb76edf7150284d8ea:/vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/Monolog/Handler/StatsDHandler.php diff --git a/vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/Monolog/Handler/StatsDHandler.php b/vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/Monolog/Handler/StatsDHandler.php new file mode 100644 index 00000000..86c6d399 --- /dev/null +++ b/vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/Monolog/Handler/StatsDHandler.php @@ -0,0 +1,120 @@ + + */ +class StatsDHandler extends AbstractProcessingHandler +{ + /** + * @var array + */ + protected $buffer = array(); + + /** + * @var string + */ + protected $prefix; + + /** + * @var statsDService + */ + protected $statsDService; + + /** + * @var statsDFactory + */ + protected $statsDFactory; + + /** + * @param StatsdClientInterface $statsDService The Service sends the packet + * @param StatsdDataFactoryInterface $statsDFactory The Factory creates the StatsDPacket + * @param string $prefix Statsd key prefix + * @param integer $level The minimum logging level at which this handler will be triggered + * @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not + */ + public function __construct(StatsdClientInterface $statsDService, StatsdDataFactoryInterface $statsDFactory = null, $prefix, $level = Logger::DEBUG, $bubble = true) + { + parent::__construct($level, $bubble); + + $this->statsDService = $statsDService; + $this->statsDFactory = $statsDFactory ? $statsDFactory : new StatsdDataFactory(); + $this->prefix = $prefix; + } + + /** + * {@inheritdoc} + */ + public function close() + { + $this->statsDService->send($this->buffer); + } + + /** + * {@inheritdoc} + */ + protected function write(array $record) + { + $records = is_array($record['formatted']) ? $record['formatted'] : array($record['formatted']); + + foreach ($records as $record) { + if (!empty($record)) { + $this->buffer[] = $this->statsDFactory->increment(sprintf('%s.%s', $this->getPrefix(), $record)); + } + } + } + + /** + * Gets the default formatter. + * + * @return FormatterInterface + */ + protected function getDefaultFormatter() + { + return new StatsDFormatter(); + } + + /** + * @param string $prefix + */ + public function setPrefix($prefix) + { + $this->prefix = $prefix; + } + + /** + * @return string + */ + public function getPrefix() + { + return $this->prefix; + } + + /** + * @param StatsdClientInterface $statsDService + */ + public function setStatsDService(StatsdClientInterface $statsDService) + { + $this->statsDService = $statsDService; + } + + /** + * @param StatsdDataFactoryInterface $statsDFactory + */ + public function setStatsDFactory(StatsdDataFactoryInterface $statsDFactory) + { + $this->statsDFactory = $statsDFactory; + } +}