| 1 |
<?php |
| 2 |
/** |
| 3 |
* Stackdriver via Fluentd handler for Monolog |
| 4 |
* |
| 5 |
* Handles all features of Stackdriver via Fluentd handler for Monolog. |
| 6 |
* |
| 7 |
* @package Handlers |
| 8 |
* @author Pierre Lannoy <https://pierre.lannoy.fr/>. |
| 9 |
* @since 1.0.0 |
| 10 |
*/ |
| 11 |
|
| 12 |
namespace Decalog\Handler; |
| 13 |
|
| 14 |
use DLMonolog\Logger; |
| 15 |
use Decalog\Plugin\Feature\DLogger; |
| 16 |
use DLMonolog\Handler\SocketHandler; |
| 17 |
use DLMonolog\Formatter\FormatterInterface; |
| 18 |
use Decalog\Formatter\StackdriverFormatter; |
| 19 |
|
| 20 |
/** |
| 21 |
* Define the Monolog Stackdriver via Fluentd handler. |
| 22 |
* |
| 23 |
* Handles all features of Stackdriver via Fluentd handler for Monolog. |
| 24 |
* |
| 25 |
* @package Handlers |
| 26 |
* @author Pierre Lannoy <https://pierre.lannoy.fr/>. |
| 27 |
* @since 1.0.0 |
| 28 |
*/ |
| 29 |
class StackdriverHandler extends SocketHandler { |
| 30 |
|
| 31 |
/** |
| 32 |
* @param string $connection_string Socket connection string. |
| 33 |
* @param integer $timeout The socket timeout. |
| 34 |
* @param int|string $level The minimum logging level at which this handler will be triggered. |
| 35 |
* @param bool $bubble Whether the messages that are handled can bubble up the stack or not. |
| 36 |
*/ |
| 37 |
public function __construct( string $connection_string, int $timeout, $level = Logger::DEBUG, bool $bubble = true ) { |
| 38 |
$new_timeout = $timeout / 1000; |
| 39 |
$old_timeout = ini_get( 'default_socket_timeout' ); |
| 40 |
// phpcs:ignore |
| 41 |
ini_set( 'default_socket_timeout', (string) $new_timeout ); |
| 42 |
parent::__construct( $connection_string, $level, $bubble ); |
| 43 |
// phpcs:ignore |
| 44 |
ini_set( 'default_socket_timeout', (string) $old_timeout ); |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* {@inheritDoc} |
| 49 |
*/ |
| 50 |
protected function getDefaultFormatter(): FormatterInterface { |
| 51 |
return new StackdriverFormatter(); |
| 52 |
} |
| 53 |
} |
| 54 |
|