-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates to Monolog 2.0 (and PHP 7.2)
- Loading branch information
Showing
5 changed files
with
30 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ composer.phar | |
phpunit.xml | ||
composer.lock | ||
.DS_Store | ||
.phpunit.result.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,9 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Monolog package. | ||
* | ||
* (c) Jordi Boggiano <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace FemtoPixel\Monolog\Handler; | ||
|
||
use Monolog\Formatter\FormatterInterface; | ||
use Monolog\Formatter\LineFormatter; | ||
use Monolog\Formatter\NormalizerFormatter; | ||
use Monolog\Handler\StreamHandler; | ||
|
||
|
@@ -19,7 +12,7 @@ | |
* | ||
* Can be used to store big loads to physical files and import them later into another system that can handle CSV | ||
* | ||
* @author Jay MOULIN <jaymoulin@gmail.com> | ||
* @author Jay MOULIN <jay@femtopixel.com> | ||
*/ | ||
class CsvHandler extends StreamHandler | ||
{ | ||
|
@@ -30,7 +23,7 @@ class CsvHandler extends StreamHandler | |
/** | ||
* @inheritdoc | ||
*/ | ||
protected function streamWrite($resource, array $record) | ||
protected function streamWrite($stream, array $record): void | ||
{ | ||
if (is_array($record['formatted'])) { | ||
foreach ($record['formatted'] as $key => $info) { | ||
|
@@ -39,17 +32,20 @@ protected function streamWrite($resource, array $record) | |
} | ||
} | ||
} | ||
$formated = (array)$record['formatted']; | ||
$formatted = (array)$record['formatted']; | ||
if (version_compare(PHP_VERSION, '5.5.4', '>=') && !defined('HHVM_VERSION')) { | ||
return fputcsv($resource, $formated, static::DELIMITER, static::ENCLOSURE, static::ESCAPE_CHAR); | ||
fputcsv($stream, $formatted, static::DELIMITER, static::ENCLOSURE, static::ESCAPE_CHAR); | ||
return; | ||
} | ||
return fputcsv($resource, $formated, static::DELIMITER, static::ENCLOSURE); | ||
fputcsv($stream, $formatted, static::DELIMITER, static::ENCLOSURE); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
* Gets the default formatter. | ||
* | ||
* Overwrite this if the LineFormatter is not a good default for your handler. | ||
*/ | ||
protected function getDefaultFormatter() | ||
protected function getDefaultFormatter(): FormatterInterface | ||
{ | ||
return new NormalizerFormatter(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,10 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Monolog package. | ||
* | ||
* (c) Jordi Boggiano <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace FemtoPixel\Monolog\Handler; | ||
|
||
use FemtoPixel\Monolog\TestCase; | ||
use Monolog\Logger; | ||
use \Monolog\Formatter\NormalizerFormatter; | ||
|
||
class CsvHandlerTest extends TestCase | ||
{ | ||
|
@@ -32,18 +24,10 @@ public function testWriteWithNormalizer() | |
{ | ||
$handle = fopen('php://memory', 'a+'); | ||
$handler = new CsvHandler($handle); | ||
$handler->setFormatter($this->getNormalizeFormatter()); | ||
$handler->setFormatter(new NormalizerFormatter); | ||
$handler->handle($this->getRecord(Logger::WARNING, 'doesn\'t fail')); | ||
fseek($handle, 0); | ||
$regexp = "~\\A'doesn''t fail',\\[\\],300,WARNING,test,'[0-9]{4}\\-[0-9]{2}+\\-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}',\\[\\]\n\\Z~"; | ||
$regexp = "~\\A'doesn''t fail',\\[\\],300,WARNING,test,[0-9]{4}\\-[0-9]{2}\\-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\\+[0-9]{2}:[0-9]{2},\\[\\]\n\\Z~"; | ||
$this->assertSame(1, preg_match($regexp, fread($handle, 100))); | ||
} | ||
|
||
/** | ||
* @return \Monolog\Formatter\NormalizerFormatter | ||
*/ | ||
protected function getNormalizeFormatter() | ||
{ | ||
return $this->getMock('Monolog\\Formatter\\NormalizerFormatter', null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,16 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Monolog package. | ||
* | ||
* (c) Jordi Boggiano <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace FemtoPixel\Monolog; | ||
|
||
use Monolog\Logger; | ||
use Monolog\Formatter\FormatterInterface; | ||
|
||
class TestCase extends \PHPUnit_Framework_TestCase | ||
class TestCase extends \PHPUnit\Framework\TestCase | ||
{ | ||
/** | ||
* @param int $level | ||
* @param string $message | ||
* @param array $context | ||
* @return array Record | ||
*/ | ||
protected function getRecord($level = Logger::WARNING, $message = 'test', $context = array()) | ||
|
@@ -32,25 +27,11 @@ protected function getRecord($level = Logger::WARNING, $message = 'test', $conte | |
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
protected function getMultipleRecords() | ||
{ | ||
return array( | ||
$this->getRecord(Logger::DEBUG, 'debug message 1'), | ||
$this->getRecord(Logger::DEBUG, 'debug message 2'), | ||
$this->getRecord(Logger::INFO, 'information'), | ||
$this->getRecord(Logger::WARNING, 'warning'), | ||
$this->getRecord(Logger::ERROR, 'error'), | ||
); | ||
} | ||
|
||
/** | ||
* @return \Monolog\Formatter\FormatterInterface | ||
* @return FormatterInterface | ||
*/ | ||
protected function getIdentityFormatter() | ||
{ | ||
$formatter = $this->getMock('Monolog\\Formatter\\FormatterInterface'); | ||
$formatter = $this->createMock(FormatterInterface::class); | ||
$formatter->expects($this->any()) | ||
->method('format') | ||
->will($this->returnCallback(function ($record) { return $record['message']; })); | ||
|