LogEntriesHandler.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. /**
  13. * @author Robert Kaufmann III <rok3@rok3.me>
  14. */
  15. class LogEntriesHandler extends SocketHandler
  16. {
  17. /**
  18. * @var string
  19. */
  20. protected $logToken;
  21. /**
  22. * @param string $token Log token supplied by LogEntries
  23. * @param boolean $useSSL Whether or not SSL encryption should be used.
  24. * @param int $level The minimum logging level to trigger this handler
  25. * @param boolean $bubble Whether or not messages that are handled should bubble up the stack.
  26. *
  27. * @throws MissingExtensionExcpetion If SSL encryption is set to true and OpenSSL is missing
  28. */
  29. public function __construct($token, $useSSL = true, $level = Logger::DEBUG, $bubble = true)
  30. {
  31. if ($useSSL && !extension_loaded('openssl')) {
  32. throw new MissingExtensionException('The OpenSSL PHP plugin is required to use SSL encrypted connection for LogEntriesHandler');
  33. }
  34. $endpoint = $useSSL ? 'ssl://data.logentries.com:443' : 'data.logentries.com:80';
  35. parent::__construct($endpoint, $level, $bubble);
  36. $this->logToken = $token;
  37. }
  38. /**
  39. * {@inheritdoc}
  40. *
  41. * @param array $record
  42. * @return string
  43. */
  44. protected function generateDataStream($record)
  45. {
  46. return $this->logToken . ' ' . $record['formatted'];
  47. }
  48. }