コード例 #1
0
ファイル: SimpleTest.php プロジェクト: rexmac/zf2
 function testComplexValues()
 {
     $fields = array('timestamp' => 0, 'priority' => 42, 'priorityName' => 'bar');
     $f = new 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 SimpleTest_TestObject1();
     $line = $f->format($fields);
     $this->assertContains($fields['message']->__toString(), $line);
     $fields['message'] = new SimpleTest_TestObject2();
     $line = $f->format($fields);
     $this->assertContains('object', $line);
 }
コード例 #2
0
ファイル: Simple.php プロジェクト: railsphp/framework
 public function format($event)
 {
     $prevFormat = null;
     /**
      * Hack: write log without priorityName.
      */
     if ($event['priorityName'] == 'NONE') {
         $this->originalFormat = $this->format;
         $this->format = trim(str_replace('%priorityName%', '', $this->format), ': ');
     }
     /**
      * Hack: write log with date.
      */
     if (!empty($event['extra']['date'])) {
         if (!$this->originalFormat) {
             $this->originalFormat = $this->format;
         }
         $this->format = '[%timestamp%] ' . $this->format;
         unset($event['extra']['date']);
     } else {
     }
     $ret = parent::format($event);
     if ($this->originalFormat) {
         $this->format = $this->originalFormat;
         $this->originalFormat = null;
     }
     return $ret;
 }
コード例 #3
0
ファイル: SimpleTest.php プロジェクト: robertodormepoco/zf2
 /**
  * @group ZF-10427
  */
 public function testDefaultFormatShouldDisplayExtraInformations()
 {
     $message = 'custom message';
     $exception = new \RuntimeException($message);
     $event = array('timestamp' => date('c'), 'message' => 'Application error', 'priority' => 2, 'priorityName' => 'CRIT', 'info' => $exception);
     $formatter = new Simple();
     $output = $formatter->format($event);
     $this->assertContains($message, $output);
 }
コード例 #4
0
ファイル: File.php プロジェクト: mb-tec/zf-log
 /**
  * @param array $aEvent
  * @param bool  $enableBacktrace
  *
  * @return string
  */
 public function format($aEvent, $enableBacktrace = true)
 {
     $this->_addEventMetadata($aEvent, '-', $enableBacktrace);
     return parent::format($aEvent);
 }
コード例 #5
0
ファイル: SimpleTest.php プロジェクト: nuklehed/zf2
 public function testAllowsSpecifyingFormatAsConstructorArgument()
 {
     $format = '[%timestamp%] %message%';
     $formatter = new Simple($format);
     $this->assertEquals($format, $formatter->format(array()));
 }
コード例 #6
0
 public function format($event)
 {
     $message = parent::format($event);
     $colorizer = new OutputFormatter(true);
     return $colorizer->format($message);
 }