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 12namespace Monolog\Handler; 13 14use Monolog\Logger; 15 16/** 17 * @author Robert Kaufmann III <rok3@rok3.me> 18 */ 19class 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 int $level The minimum logging level to trigger this handler 30 * @param bool $bubble Whether or not messages that are handled should bubble up the stack. 31 * 32 * @throws MissingExtensionException If SSL encryption is set to true and OpenSSL is missing 33 */ 34 public function __construct($token, $useSSL = true, $level = Logger::DEBUG, $bubble = true) 35 { 36 if ($useSSL && !extension_loaded('openssl')) { 37 throw new MissingExtensionException('The OpenSSL PHP plugin is required to use SSL encrypted connection for LogEntriesHandler'); 38 } 39 40 $endpoint = $useSSL ? 'ssl://data.logentries.com:443' : 'data.logentries.com:80'; 41 parent::__construct($endpoint, $level, $bubble); 42 $this->logToken = $token; 43 } 44 45 /** 46 * {@inheritdoc} 47 * 48 * @param array $record 49 * @return string 50 */ 51 protected function generateDataStream($record) 52 { 53 return $this->logToken . ' ' . $record['formatted']; 54 } 55} 56