publish() public method

Publishes a GELFMessage, returns false if an error occured during write
public publish ( GELFMessage $message ) : boolean
$message GELFMessage
return boolean
 /**
  * Places event line into array of lines to be used as message body.
  *
  * @param array $event Event data
  * @throws Zend_Log_Exception
  */
 protected function _write($event)
 {
     try {
         $event = Mage::helper('firegento_logger')->getEventObjectFromArray($event);
         Mage::helper('firegento_logger')->addEventMetadata($event);
         $message = $event->getMessage();
         $eofMessageFirstLine = strpos($message, "\n");
         $shortMessage = false === $eofMessageFirstLine ? $message : substr($message, 0, $eofMessageFirstLine);
         $msg = new GELFMessage();
         $msg->setTimestamp(microtime(true));
         $msg->setShortMessage($shortMessage);
         if ($event->getBacktrace()) {
             $msg->setFullMessage($message . "\n\nBacktrace:\n" . $event->getBacktrace());
         } else {
             $msg->setFullMessage($message);
         }
         $msg->setHost(gethostname());
         $msg->setLevel($event->getPriority());
         $msg->setFacility($this->_options['app_name'] . $this->_options['filename']);
         $msg->setFile($event->getFile());
         $msg->setLine($event->getLine());
         $msg->setAdditional('store_code', $event->getStoreCode());
         $msg->setAdditional('time_elapsed', $event->getTimeElapsed());
         $msg->setHost(php_uname('n'));
         foreach (array('getRequestMethod', 'getRequestUri', 'getRemoteIp', 'getHttpUserAgent') as $method) {
             if (is_callable(array($event, $method)) && $event->{$method}()) {
                 $msg->setAdditional(lcfirst(substr($method, 3)), $event->{$method}());
             }
         }
         $this->_publisher->publish($msg);
     } catch (Exception $e) {
         throw new Zend_Log_Exception($e->getMessage(), $e->getCode());
     }
 }
Example #2
0
 /**
  * Places event line into array of lines to be used as message body.
  *
  * @param array $event Event data
  * @return void
  */
 protected function _write($event)
 {
     try {
         Mage::helper('hackathon_logger')->addEventMetadata($event);
         $eofMessageFirstLine = strpos($event['message'], "\n");
         $shortMessage = FALSE === $eofMessageFirstLine ? $event['message'] : substr($event['message'], 0, $eofMessageFirstLine);
         $msg = new GELFMessage();
         $msg->setTimestamp(microtime(TRUE));
         $msg->setShortMessage($shortMessage);
         if ($event['backtrace']) {
             $msg->setFullMessage($event['message'] . "\n\nBacktrace:\n" . $event['backtrace']);
         } else {
             $msg->setFullMessage($event['message']);
         }
         $msg->setHost(gethostname());
         $msg->setLevel($event['priority']);
         $msg->setFacility($this->_options['app_name'] . $this->_options['filename']);
         $msg->setFile($event['file']);
         $msg->setLine($event['line']);
         $msg->setAdditional('store_code', $event['store_code']);
         $msg->setAdditional('time_elapsed', $event['time_elapsed']);
         $msg->setHost(php_uname('n'));
         foreach (array('REQUEST_METHOD', 'REQUEST_URI', 'REMOTE_IP', 'HTTP_USER_AGENT') as $key) {
             if (!empty($event[$key])) {
                 $msg->setAdditional($key, $event[$key]);
             }
         }
         $this->_publisher->publish($msg);
     } catch (Exception $e) {
         throw new Zend_Log_Exception($e->getMessage(), $e->getCode());
     }
 }
Example #3
0
 public static function init($host = '127.0.0.1', $port = \GELFMessagePublisher::GRAYLOG2_DEFAULT_PORT)
 {
     $publisher = new \GELFMessagePublisher($host, $port);
     return function ($info) use($publisher) {
         $message = new \GELFMessage();
         $message->setHost($info['machine']);
         $message->setLevel($info['level']);
         if (is_array($info['message'])) {
             $message->setShortMessage($info['message'][0]);
             $message->setFullMessage($info['message'][0]);
             $message->setFile($info['message'][1]);
             $message->setLine($info['message'][2]);
         } else {
             $message->setShortMessage($info['message']);
             $message->setFullMessage($info['message']);
         }
         $publisher->publish($message);
     };
 }
Example #4
0
<?php

require 'GELFMessage.php';
require 'GELFMessagePublisher.php';
$message = new GELFMessage();
$message->setShortMessage('something is broken.');
$message->setFullMessage("lol full message!");
$message->setHost('somehost');
$message->setLevel(GELFMessage::CRITICAL);
$message->setFile('/var/www/example.php');
$message->setLine(1337);
$message->setAdditional("something", "foo");
$message->setAdditional("something_else", "bar");
$publisher = new GELFMessagePublisher('172.16.22.30');
$publisher->publish($message);