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); }
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; }
/** * @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); }
/** * @param array $aEvent * @param bool $enableBacktrace * * @return string */ public function format($aEvent, $enableBacktrace = true) { $this->_addEventMetadata($aEvent, '-', $enableBacktrace); return parent::format($aEvent); }
public function testAllowsSpecifyingFormatAsConstructorArgument() { $format = '[%timestamp%] %message%'; $formatter = new Simple($format); $this->assertEquals($format, $formatter->format(array())); }
public function format($event) { $message = parent::format($event); $colorizer = new OutputFormatter(true); return $colorizer->format($message); }