public function testSplitWorksOnEmptyMsg() { $handler = new SyslogUdpHandler("127.0.0.1", 514, "authpriv"); $handler->setFormatter($this->getIdentityFormatter()); $socket = $this->getMock('\\Monolog\\Handler\\SyslogUdp\\UdpSocket', array('write'), array('lol', 'lol')); $socket->expects($this->never())->method('write'); $handler->setSocket($socket); $handler->handle($this->getRecordWithMessage(null)); }
public function testWeSplitIntoLines() { $handler = new SyslogUdpHandler("127.0.0.1", 514, "authpriv"); $handler->setFormatter(new \Monolog\Formatter\ChromePHPFormatter()); $socket = $this->getMock('\\Monolog\\Handler\\SyslogUdp\\UdpSocket', array('write'), array('lol', 'lol')); $socket->expects($this->at(0))->method('write')->with("lol", "<" . (LOG_AUTHPRIV + LOG_WARNING) . ">: "); $socket->expects($this->at(1))->method('write')->with("hej", "<" . (LOG_AUTHPRIV + LOG_WARNING) . ">: "); $handler->setSocket($socket); $handler->handle($this->getRecordWithMessage("hej\nlol")); }
/** * Boot connector with given host, port and log message prefix. * If host or port are omitted, we'll try to get them from the environment * variables PAPERTRAIL_HOST and PAPERTRAIL_PORT. * @param string $host Papertrail log server, ie log.papertrailapp.com * @param int $port Papertrail port number for log server * @param string $prefix Prefix to use for each log message * @return \Monolog\Logger */ public static function boot($host = null, $port = null, $prefix = '') { $host or $host = getenv('PAPERTRAIL_HOST'); $port or $port = getenv('PAPERTRAIL_PORT'); $prefix and $prefix = "[{$prefix}] "; $monolog = static::getMonolog(); $syslog = new SyslogUdpHandler($host, $port); $formatter = new LineFormatter("{$prefix}%channel%.%level_name%: %message% %extra%"); $syslog->setFormatter($formatter); $monolog->pushHandler($syslog); return $monolog; }
public function write(Entry $entry) { if (!$this->isTriggered($entry)) { return; } $output = "%channel%.%level_name%: %message%"; $formatter = new LineFormatter($output); $name = env('LOGGER_APP_NAME') . '-' . $entry->getChannel(); $log = new MonologLogger($name); $syslogHandler = new SyslogUdpHandler(env('LOGGER_PAPERTRAIL_HOST'), env('LOGGER_PAPERTRAIL_PORT')); $syslogHandler->setFormatter($formatter); $log->pushHandler($syslogHandler); $log->addRecord($entry->getCode(), $entry->getMessage(), $entry->getContext()); }
protected static function parseRemote(Logger $logger, $conf) { $remote = explode("::", $conf); if (sizeof($remote) != 4) { return; } $host = $remote[0]; $port = $remote[1]; $facility = self::getFacility($remote[2]); $level = self::getLevel($remote[3]); $handler = new SyslogUdpHandler($host, $port, $facility, $level); $formatter = new LineFormatter("%datetime% - %channel% - %level_name% - %message%\n"); $handler->setFormatter($formatter); $logger->pushHandler($handler); }
/** * Konsturktor */ public function __construct() { $logTitle = tpenv('TP_LOG_NAME', 'TP-Log'); $log = tpenv('TP_LOG', 'production'); $this->log = new Logger($logTitle); if ($log == 'developement') { $this->log->pushHandler(new StreamHandler('php://stderr', Logger::DEBUG)); } elseif ($log == 'papertrail') { // set format $output = "%channel%.%level_name%: %message%"; $formatter = new LineFormatter($output); // Setup the logger $host = tpenv('TP_LOG_PAPERTRAIL_HOST', 'HOST'); $port = tpenv('TP_LOG_PAPERTRAIL_PORT', 'PORT'); $syslogHandler = new SyslogUdpHandler($host . ".papertrailapp.com", $port); $syslogHandler->setFormatter($formatter); $this->log->pushHandler($syslogHandler, Logger::INFO); } else { $this->log->pushHandler(new StreamHandler(storage_path() . '/logs/' . $logTitle . '.log', Logger::DEBUG)); } }
/** * @param Application $app */ public function register(Application $app) { $app['papertrailHandler'] = $app->share(function () use($app) { if (!isset($app['host'])) { throw new \Exception("Host undefined"); } if (!isset($app['port'])) { throw new \Exception("Port undefined"); } if (!isset($app['prefix'])) { $app['prefix'] = ''; } else { $app['prefix'] = sprintf('[%s]', $app['prefix']); } // Set the format of message $output = $app['prefix'] . "%channel%.%level_name%: %message%"; $formatter = new LineFormatter($output); // Setup the logger handler $papertrailHandler = new SyslogUdpHandler(sprintf("%s.papertrailapp.com", $app['host']), $app['port']); $papertrailHandler->setFormatter($formatter); return $papertrailHandler; }); }
/** * @param string $appname Application name to report to syslog * @param string $host Syslog host * @param int $port Syslog port * @param int $facility Syslog message facility * @param string $level The minimum logging level at which this handler * will be triggered * @param bool $bubble Whether the messages that are handled can bubble up * the stack or not */ public function __construct($appname, $host, $port = 514, $facility = LOG_USER, $level = Logger::DEBUG, $bubble = true) { parent::__construct($host, $port, $facility, $level, $bubble); $this->appname = $appname; $this->hostname = php_uname('n'); }
/** * Конструктор. * @param string $sourceAppName имя приложения-отправителя * @param string $sourceHostName имя хоста-отправителя * @param string $syslogHost syslog-хост * @param int $syslogPort syslog-порт * @param mixed $syslogFacility источник логирования * @param integer $level The minimum logging level at which this handler will be triggered * @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not */ public function __construct($sourceAppName, $sourceHostName, $syslogHost, $syslogPort, $syslogFacility = LOG_USER, $level = Logger::DEBUG, $bubble = true) { parent::__construct($syslogHost, $syslogPort, $syslogFacility, $level, $bubble); $this->appName = $sourceAppName; $this->hostName = $sourceHostName; }