1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-10 15:14:14 +02:00

Changed the FormatterInterface to return only the formatted message and added a batch formatting method

This commit is contained in:
Christophe Coevoet
2011-05-07 00:44:20 +02:00
parent d7f98df9ab
commit 7ebcc6420f
9 changed files with 69 additions and 28 deletions

View File

@@ -18,13 +18,13 @@ class JsonFormatterTest extends \PHPUnit_Framework_TestCase
public function testFormat()
{
$formatter = new JsonFormatter();
$record = $formatter->format($msg = array(
$message = $formatter->format($msg = array(
'level_name' => 'WARNING',
'channel' => 'log',
'message' => array('foo'),
'datetime' => new \DateTime,
'extra' => array(),
));
$this->assertEquals(json_encode($msg), $record['message']);
$this->assertEquals(json_encode($msg), $message);
}
}

View File

@@ -18,20 +18,20 @@ class LineFormatterTest extends \PHPUnit_Framework_TestCase
public function testDefFormatWithString()
{
$formatter = new LineFormatter(null, 'Y-m-d');
$record = $formatter->format(array(
$message = $formatter->format(array(
'level_name' => 'WARNING',
'channel' => 'log',
'message' => 'foo',
'datetime' => new \DateTime,
'extra' => array(),
));
$this->assertEquals('['.date('Y-m-d').'] log.WARNING: foo '."\n", $record['message']);
$this->assertEquals('['.date('Y-m-d').'] log.WARNING: foo '."\n", $message);
}
public function testDefFormatWithArray()
{
$formatter = new LineFormatter(null, 'Y-m-d');
$record = $formatter->format(array(
$message = $formatter->format(array(
'level_name' => 'ERROR',
'channel' => 'meh',
'datetime' => new \DateTime,
@@ -41,19 +41,19 @@ class LineFormatterTest extends \PHPUnit_Framework_TestCase
'baz' => 'qux',
)
));
$this->assertEquals('['.date('Y-m-d').'] meh.ERROR: message(foo: bar, baz: qux) '."\n", $record['message']);
$this->assertEquals('['.date('Y-m-d').'] meh.ERROR: message(foo: bar, baz: qux) '."\n", $message);
}
public function testDefFormatExtras()
{
$formatter = new LineFormatter(null, 'Y-m-d');
$record = $formatter->format(array(
$message = $formatter->format(array(
'level_name' => 'ERROR',
'channel' => 'meh',
'datetime' => new \DateTime,
'extra' => array('ip' => '127.0.0.1'),
'message' => 'log',
));
$this->assertEquals('['.date('Y-m-d').'] meh.ERROR: log extra(ip: 127.0.0.1)'."\n", $record['message']);
$this->assertEquals('['.date('Y-m-d').'] meh.ERROR: log extra(ip: 127.0.0.1)'."\n", $message);
}
}

View File

@@ -22,11 +22,11 @@ class WildfireFormatterTest extends \PHPUnit_Framework_TestCase
{
$wildfire = new WildfireFormatter();
$record = $wildfire->format($record);
$message = $wildfire->format($record);
$this->assertEquals(
'70|[{"Type":"ERROR","File":"","Line":""},"meh: log extra(ip: 127.0.0.1)"]|',
$record['message']
$message
);
}

View File

@@ -36,7 +36,7 @@ class TestCase extends \PHPUnit_Framework_TestCase
$formatter = $this->getMock('Monolog\\Formatter\\FormatterInterface');
$formatter->expects($this->any())
->method('format')
->will($this->returnArgument(0));
->will($this->returnCallback(function($record) { return $record['message']; }));
return $formatter;
}