| 1 |
<?php |
| 2 |
|
| 3 |
/* |
| 4 |
* This file is part of the Monolog package. |
| 5 |
* |
| 6 |
* (c) Jordi Boggiano <j.boggiano@seld.be> |
| 7 |
* |
| 8 |
* For the full copyright and license information, please view the LICENSE |
| 9 |
* file that was distributed with this source code. |
| 10 |
*/ |
| 11 |
|
| 12 |
/** |
| 13 |
* Handler to send messages to a Graylog2 (http://www.graylog2.org) server |
| 14 |
* |
| 15 |
* @author Matt Lehner <mlehner@gmail.com> |
| 16 |
*/ |
| 17 |
class Monolog_Handler_LegacyGelfHandler extends Monolog_Handler_AbstractProcessingHandler |
| 18 |
{ |
| 19 |
/** |
| 20 |
* @var Gelf_Publisher the publisher object that sends the message to the server |
| 21 |
*/ |
| 22 |
protected $publisher; |
| 23 |
|
| 24 |
/** |
| 25 |
* @param Gelf_Publisher $publisher a publisher object |
| 26 |
* @param integer $level The minimum logging level at which this handler will be triggered |
| 27 |
* @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not |
| 28 |
*/ |
| 29 |
public function __construct(Gelf_Publisher $publisher, $level = Monolog_Logger::DEBUG, $bubble = true) |
| 30 |
{ |
| 31 |
parent::__construct($level, $bubble); |
| 32 |
|
| 33 |
$this->publisher = $publisher; |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* {@inheritdoc} |
| 38 |
*/ |
| 39 |
public function close() |
| 40 |
{ |
| 41 |
$this->publisher = null; |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* {@inheritdoc} |
| 46 |
*/ |
| 47 |
protected function write(array $record) |
| 48 |
{ |
| 49 |
$this->publisher->publish($record['formatted']); |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* {@inheritDoc} |
| 54 |
*/ |
| 55 |
protected function getDefaultFormatter() |
| 56 |
{ |
| 57 |
return new Monolog_Formatter_LegacyGelfMessageFormatter(); |
| 58 |
} |
| 59 |
} |
| 60 |
|