public function testDefFormatWithPreviousException() { $formatter = new LineFormatter(null, 'Y-m-d'); $previous = new \LogicException('Wut?'); $message = $formatter->format(array('level_name' => 'CRITICAL', 'channel' => 'core', 'context' => array('exception' => new \RuntimeException('Foo', 0, $previous)), 'datetime' => new \DateTime(), 'extra' => array(), 'message' => 'foobar')); $path = str_replace('\\/', '/', json_encode(__FILE__)); $this->assertEquals('[' . date('Y-m-d') . '] core.CRITICAL: foobar {"exception":"[object] (RuntimeException: Foo at ' . substr($path, 1, -1) . ':' . (__LINE__ - 8) . ', LogicException: Wut? at ' . substr($path, 1, -1) . ':' . (__LINE__ - 12) . ')"} []' . "\n", $message); }
public function testDefFormatWithObject() { $formatter = new LineFormatter(null, 'Y-m-d'); $message = $formatter->format(array('level_name' => 'ERROR', 'channel' => 'meh', 'context' => array(), 'datetime' => new \DateTime(), 'extra' => array('foo' => new TestFoo(), 'bar' => new TestBar(), 'baz' => array(), 'res' => fopen('php://memory', 'rb')), 'message' => 'foobar')); if (version_compare(PHP_VERSION, '5.4.0', '>=')) { $this->assertEquals('[' . date('Y-m-d') . '] meh.ERROR: foobar [] {"foo":"[object] (Monolog\\\\Formatter\\\\TestFoo: {\\"foo\\":\\"foo\\"})","bar":"[object] (Monolog\\\\Formatter\\\\TestBar: {})","baz":[],"res":"[resource]"}' . "\n", $message); } else { $this->assertEquals('[' . date('Y-m-d') . '] meh.ERROR: foobar [] {"foo":"[object] (Monolog\\Formatter\\TestFoo: {"foo":"foo"})","bar":"[object] (Monolog\\Formatter\\TestBar: {})","baz":[],"res":"[resource]"}' . "\n", $message); } }
public function testFormatShouldNotStripInlineLineBreaksWhenFlagIsSet() { $formatter = new LineFormatter(null, 'Y-m-d', true); $message = $formatter->format(array('message' => "foo\nbar", 'context' => array(), 'extra' => array())); $this->assertRegExp('/foo\\nbar/', $message); }
/** * {@inheritdoc} */ public function format(array $record) { return preg_replace(ColorLineFormatter::COLOR_PATTERN, '', parent::format($record)); }
/** * {@inheritdoc} */ public function format(array $record) { $output = parent::format($record); return preg_replace_callback(self::COLOR_PATTERN, array($this, 'applyMethods'), $output); }