mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-10 23:24:02 +02:00
Merge pull request #309 from apancutt/master
Added support for Loggly batch uploads
This commit is contained in:
@@ -16,6 +16,18 @@ use Monolog\TestCase;
|
||||
|
||||
class JsonFormatterTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers Monolog\Formatter\JsonFormatter::__construct
|
||||
* @covers Monolog\Formatter\JsonFormatter::getBatchMode
|
||||
*/
|
||||
public function testConstruct()
|
||||
{
|
||||
$formatter = new JsonFormatter();
|
||||
$this->assertEquals(JsonFormatter::BATCH_MODE_JSON, $formatter->getBatchMode());
|
||||
$formatter = new JsonFormatter(JsonFormatter::BATCH_MODE_NEWLINES);
|
||||
$this->assertEquals(JsonFormatter::BATCH_MODE_NEWLINES, $formatter->getBatchMode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Monolog\Formatter\JsonFormatter::format
|
||||
*/
|
||||
@@ -28,6 +40,7 @@ class JsonFormatterTest extends TestCase
|
||||
|
||||
/**
|
||||
* @covers Monolog\Formatter\JsonFormatter::formatBatch
|
||||
* @covers Monolog\Formatter\JsonFormatter::formatBatchJson
|
||||
*/
|
||||
public function testFormatBatch()
|
||||
{
|
||||
@@ -38,4 +51,22 @@ class JsonFormatterTest extends TestCase
|
||||
);
|
||||
$this->assertEquals(json_encode($records), $formatter->formatBatch($records));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Monolog\Formatter\JsonFormatter::formatBatch
|
||||
* @covers Monolog\Formatter\JsonFormatter::formatBatchNewlines
|
||||
*/
|
||||
public function testFormatBatchNewlines()
|
||||
{
|
||||
|
||||
$formatter = new JsonFormatter(JsonFormatter::BATCH_MODE_NEWLINES);
|
||||
$records = $expected = array(
|
||||
$this->getRecord(Logger::WARNING),
|
||||
$this->getRecord(Logger::DEBUG),
|
||||
);
|
||||
array_walk($expected, function(&$value, $key) {
|
||||
$value = json_encode($value);
|
||||
});
|
||||
$this->assertEquals(implode("\n", $expected), $formatter->formatBatch($records));
|
||||
}
|
||||
}
|
||||
|
41
tests/Monolog/Formatter/LogglyFormatterTest.php
Normal file
41
tests/Monolog/Formatter/LogglyFormatterTest.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Monolog package.
|
||||
*
|
||||
* (c) Jordi Boggiano <j.boggiano@seld.be>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Monolog\Formatter;
|
||||
|
||||
use Monolog\Logger;
|
||||
use Monolog\TestCase;
|
||||
|
||||
class LogglyFormatterTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers Monolog\Formatter\LogglyFormatter::__construct
|
||||
*/
|
||||
public function testConstruct()
|
||||
{
|
||||
$formatter = new LogglyFormatter();
|
||||
$this->assertEquals(LogglyFormatter::BATCH_MODE_NEWLINES, $formatter->getBatchMode());
|
||||
$formatter = new LogglyFormatter(LogglyFormatter::BATCH_MODE_JSON);
|
||||
$this->assertEquals(LogglyFormatter::BATCH_MODE_JSON, $formatter->getBatchMode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Monolog\Formatter\LogglyFormatter::format
|
||||
*/
|
||||
public function testFormat()
|
||||
{
|
||||
$formatter = new LogglyFormatter();
|
||||
$record = $this->getRecord();
|
||||
$formatted_decoded = json_decode($formatter->format($record), true);
|
||||
$this->assertArrayHasKey("timestamp", $formatted_decoded);
|
||||
$this->assertEquals(new \DateTime($formatted_decoded["timestamp"]), $record["datetime"]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user