setHost() public method

public setHost ( string $host ) : GELFMessage
$host string
return GELFMessage
Exemplo n.º 1
0
 public function testGelfMessage()
 {
     $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");
     $this->assertEquals(array('version' => null, 'timestamp' => null, 'short_message' => 'something is broken.', 'full_message' => 'lol full message!', 'facility' => null, 'host' => 'somehost', 'level' => GELFMessage::CRITICAL, 'file' => '/var/www/example.php', 'line' => 1337, '_something' => 'foo', '_something_else' => 'bar'), $message->toArray());
 }
Exemplo n.º 2
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);
     };
 }
 /**
  * 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());
     }
 }
Exemplo n.º 4
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());
     }
 }
Exemplo n.º 5
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);
Exemplo n.º 6
0
<?php

require 'gelf.php';
$gelf = new GELFMessage('localhost', 12201);
$gelf->setShortMessage('something is broken.');
$gelf->setFullMessage("lol full message!");
$gelf->setHost('somehost');
$gelf->setLevel(2);
$gelf->setFile('/var/www/example.php');
$gelf->setLine(1337);
$gelf->setAdditional("something", "foo");
$gelf->setAdditional("something_else", "bar");
$gelf->send();