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"));
 }
Beispiel #3
0
 /**
  * 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;
 }
Beispiel #4
0
 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;
     });
 }