| 1 |
<?php declare(strict_types=1); |
| 2 |
|
| 3 |
/* |
| 4 |
* This file is part of the Monolog package. |
| 5 |
* |
| 6 |
* (c) Jordi Boggiano <[email protected]> |
| 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 |
namespace Monolog\Handler; |
| 13 |
|
| 14 |
use Monolog\Logger; |
| 15 |
|
| 16 |
/** |
| 17 |
* @author Robert Kaufmann III <[email protected]> |
| 18 |
*/ |
| 19 |
class LogEntriesHandler extends SocketHandler |
| 20 |
{ |
| 21 |
/** |
| 22 |
* @var string |
| 23 |
*/ |
| 24 |
protected $logToken; |
| 25 |
|
| 26 |
/** |
| 27 |
* @param string $token Log token supplied by LogEntries |
| 28 |
* @param bool $useSSL Whether or not SSL encryption should be used. |
| 29 |
* @param string $host Custom hostname to send the data to if needed |
| 30 |
* |
| 31 |
* @throws MissingExtensionException If SSL encryption is set to true and OpenSSL is missing |
| 32 |
*/ |
| 33 |
public function __construct(string $token, bool $useSSL = true, $level = Logger::DEBUG, bool $bubble = true, string $host = 'data.logentries.com') |
| 34 |
{ |
| 35 |
if ($useSSL && !extension_loaded('openssl')) { |
| 36 |
throw new MissingExtensionException('The OpenSSL PHP plugin is required to use SSL encrypted connection for LogEntriesHandler'); |
| 37 |
} |
| 38 |
|
| 39 |
$endpoint = $useSSL ? 'ssl://' . $host . ':443' : $host . ':80'; |
| 40 |
parent::__construct($endpoint, $level, $bubble); |
| 41 |
$this->logToken = $token; |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* {@inheritDoc} |
| 46 |
*/ |
| 47 |
protected function generateDataStream(array $record): string |
| 48 |
{ |
| 49 |
return $this->logToken . ' ' . $record['formatted']; |
| 50 |
} |
| 51 |
} |
| 52 |
|