public function testDefaultFormat()
 {
     $f = new Zend_Log_Formatter_Simple();
     $line = $f->format($message = 'message', $priority = 1);
     $this->assertContains($message, $line);
     $this->assertContains((string) $priority, $line);
 }
 public function testDefaultFormat()
 {
     $fields = array('timestamp' => 0, 'message' => 'foo', 'priority' => 42, 'priorityName' => 'bar');
     $f = new Zend_Log_Formatter_Simple();
     $line = $f->format($fields);
     $this->assertContains((string) $fields['timestamp'], $line);
     $this->assertContains($fields['message'], $line);
     $this->assertContains($fields['priorityName'], $line);
     $this->assertContains((string) $fields['priority'], $line);
 }
Exemple #3
0
 function testComplexValues()
 {
     $fields = array('timestamp' => 0, 'priority' => 42, 'priorityName' => 'bar');
     $f = new Zend_Log_Formatter_Simple();
     $fields['message'] = 'Foo';
     $line = $f->format($fields);
     $this->assertContains($fields['message'], $line);
     $fields['message'] = 10;
     $line = $f->format($fields);
     $this->assertContains($fields['message'], $line);
     $fields['message'] = 10.5;
     $line = $f->format($fields);
     $this->assertContains($fields['message'], $line);
     $fields['message'] = true;
     $line = $f->format($fields);
     $this->assertContains('1', $line);
     $fields['message'] = fopen('php://stdout', 'w');
     $line = $f->format($fields);
     $this->assertContains('Resource id ', $line);
     fclose($fields['message']);
     $fields['message'] = range(1, 10);
     $line = $f->format($fields);
     $this->assertContains('array', $line);
     $fields['message'] = new Zend_Log_Formatter_SimpleTest_TestObject1();
     $line = $f->format($fields);
     $this->assertContains($fields['message']->__toString(), $line);
     $fields['message'] = new Zend_Log_Formatter_SimpleTest_TestObject2();
     $line = $f->format($fields);
     $this->assertContains('object', $line);
 }
Exemple #4
0
 public function __construct()
 {
     $format = '';
     $format .= 'Timestamp:          %timestamp%' . PHP_EOL;
     $format .= 'Priority:           %priorityName% (%priority%)' . PHP_EOL;
     $format .= 'Message:            %message%' . PHP_EOL;
     $format .= PHP_EOL;
     $format .= 'Hostname:           ' . php_uname('n') . PHP_EOL;
     $format .= 'APPLICATION_ENV:    ' . APPLICATION_ENV . PHP_EOL;
     $format .= 'APPLICATION_PATH:   ' . APPLICATION_PATH . PHP_EOL;
     $format .= PHP_EOL;
     $format .= 'Trace:' . PHP_EOL;
     $format .= '%trace%' . PHP_EOL;
     $format .= PHP_EOL;
     $format .= '$_SERVER:' . PHP_EOL;
     $format .= var_export($_SERVER, true) . PHP_EOL;
     $format .= PHP_EOL;
     $format .= '$_REQUEST:' . PHP_EOL;
     $format .= var_export($_REQUEST, true) . PHP_EOL;
     $format .= PHP_EOL;
     $format .= '$_GET:' . PHP_EOL;
     $format .= var_export($_GET, true) . PHP_EOL;
     $format .= PHP_EOL;
     $format .= '$_POST:' . PHP_EOL;
     $format .= var_export($_POST, true) . PHP_EOL;
     $format .= PHP_EOL;
     $format .= '$_COOKIE:' . PHP_EOL;
     $format .= var_export($_COOKIE, true) . PHP_EOL;
     $format .= PHP_EOL;
     $format .= '$_ENV:' . PHP_EOL;
     $format .= var_export($_ENV, true) . PHP_EOL;
     $format .= PHP_EOL;
     parent::__construct($format);
 }
Exemple #5
0
 /**
  * Formats data into a single line to be written by the writer.
  *
  * @param  array    $event    event data
  * @return string             formatted line to write to the log
  */
 public function format($event)
 {
     if (!self::$_sessionId) {
         self::$_sessionId = substr(Tinebase_Record_Abstract::generateUID(), 0, 5);
     }
     $user = Tinebase_Core::getUser();
     $userName = $user && is_object($user) ? $user->accountDisplayName : '-- none --';
     $output = parent::format($event);
     return self::$_sessionId . " {$userName} - {$output}";
 }
Exemple #6
0
 /**
  * Formats data into a single line to be written by the writer.
  *
  * @param  array    $event    event data
  * @return string             formatted line to write to the log
  */
 public function format($event)
 {
     $event["timestamp"] = date("Y-m-d H:i:s");
     if (Zend_Registry::isRegistered('role')) {
         $role = Zend_Registry::get('role');
     } else {
         $role = "-";
     }
     $event["role"] = $role;
     return parent::format($event) . PHP_EOL;
 }
 /**
  * Formats data into a single line to be written by the writer.
  *
  * @param  array $event event data
  * @return string             formatted line to write to the log
  */
 public function format($event)
 {
     $types = ['line', 'timestamp', 'priority', 'message'];
     $styles = [];
     switch ($event['priority']) {
         case \Zend_Log::EMERG:
             $styles['line'] = 'fg=white;bg=red;options=underscore';
             break;
         case \Zend_Log::ALERT:
             $styles['line'] = 'fg=white;bg=red';
             break;
         case \Zend_Log::CRIT:
             $styles['line'] = 'fg=red';
             $styles['priority'] = 'fg=white;bg=red';
             break;
         case \Zend_Log::ERR:
             $styles['timestamp'] = 'fg=red';
             $styles['priority'] = 'fg=white;bg=red';
             break;
         case \Zend_Log::WARN:
             $styles['timestamp'] = 'fg=yellow';
             $styles['priority'] = 'bg=yellow;fg=black';
             break;
         case \Zend_Log::NOTICE:
             $styles['timestamp'] = 'fg=blue';
             $styles['priority'] = 'fg=blue';
             break;
         case \Zend_Log::DEBUG:
             $styles['timestamp'] = 'fg=cyan';
             $styles['priority'] = 'fg=black;bg=cyan';
             break;
     }
     foreach ($types as $type) {
         if (isset($styles[$type])) {
             $event[$type . 'StyleStart'] = sprintf('<%s>', $styles[$type]);
             $event[$type . 'StyleEnd'] = '</>';
         } else {
             $event[$type . 'StyleStart'] = '';
             $event[$type . 'StyleEnd'] = '';
         }
     }
     return parent::format($event);
 }
 /**
  * @group ZF-9176
  */
 public function testFactory()
 {
     $options = array('format' => '%timestamp% [%priority%]: %message% -- %info%');
     $formatter = Zend_Log_Formatter_Simple::factory($options);
     $this->assertType('Zend_Log_Formatter_Simple', $formatter);
 }
 /**
  * Formats data into a single line to be written by the writer.
  *
  * @param  FireGento_Logger_Model_Event $event           Event Data
  * @param  bool                         $enableBacktrace Backtrace Flag
  * @return string formatted line to write to the log
  */
 public function format($event, $enableBacktrace = false)
 {
     Mage::helper('firegento_logger')->addEventMetadata($event, '-', $enableBacktrace);
     return parent::format($event->getEventDataArray());
 }
 /**
  * Formats data into a single line to be written by the writer.
  *
  * @param  FireGento_Logger_Model_Event $event Event Data
  * @return string formatted line to write to the log
  */
 public function format($event)
 {
     return parent::format($event->getEventDataArray());
 }
 /**
  * Add session id in front of log line
  *
  * @param  array    $event    event data
  * @return string             formatted line to write to the log
  */
 public function format($event)
 {
     $output = parent::format($event);
     $output = str_replace($this->_search, $this->_replace, $output);
     $timelog = '';
     if (self::$_logdifftime || self::$_logruntime) {
         $currenttime = microtime(true);
         if (self::$_logruntime) {
             $timelog = Tinebase_Helper::formatMicrotimeDiff($currenttime - self::$_starttime) . ' ';
         }
         if (self::$_logdifftime) {
             $timelog .= Tinebase_Helper::formatMicrotimeDiff($currenttime - (self::$_lastlogtime ? self::$_lastlogtime : $currenttime)) . ' ';
             self::$_lastlogtime = $currenttime;
         }
     }
     return self::getPrefix() . ' ' . self::getUsername() . ' ' . $timelog . '- ' . $output;
 }
Exemple #12
0
 /**
  * Formats data into a single line to be written by the writer.
  *
  * @param array $event
  * @param bool $enableBacktrace
  * @return string             formatted line to write to the log
  */
 public function format($event, $enableBacktrace = FALSE)
 {
     Mage::helper('hackathon_logger')->addEventMetadata($event, '-', $enableBacktrace);
     return parent::format($event);
 }