Skip to content

Commit ae6d1d5

Browse files
committed
Updates to Monolog 2.0 (and PHP 7.2)
1 parent b6d5335 commit ae6d1d5

File tree

5 files changed

+30
-67
lines changed

5 files changed

+30
-67
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ composer.phar
44
phpunit.xml
55
composer.lock
66
.DS_Store
7+
.phpunit.result.cache

composer.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,22 @@
88
"authors": [
99
{
1010
"name": "Jay MOULIN",
11-
"email": "jaymoulin@gmail.com",
12-
"homepage": "http://github.com/jaymoulin"
11+
"email": "jay@femtopixel.com",
12+
"homepage": "http://github.com/femtopixel"
1313
}
1414
],
1515
"support": {
1616
"issues": "http://github.com/femtopixel/monolog-csvhandler/issues",
1717
"source": "https://github.com/femtopixel/monolog-csvhandler"
1818
},
1919
"require": {
20-
"php": ">=5.3.0",
21-
"monolog/monolog": "^1.22.0",
22-
"psr/log": "~1.0"
20+
"php": ">=7.2.0",
21+
"monolog/monolog": "^2.0",
22+
"psr/log": "~1.0",
23+
"ext-json": "*"
2324
},
2425
"require-dev": {
25-
"phpunit/phpunit": "~4.5"
26+
"phpunit/phpunit": "^8.0"
2627
},
2728
"autoload": {
2829
"psr-4": {"FemtoPixel\\Monolog\\": "src/Monolog"}

src/Monolog/Handler/CsvHandler.php

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
11
<?php
22

3-
/*
4-
* This file is part of the Monolog package.
5-
*
6-
* (c) Jordi Boggiano <j.boggiano@seld.be>
7-
*
8-
* For the full copyright and license information, please view the LICENSE
9-
* file that was distributed with this source code.
10-
*/
11-
123
namespace FemtoPixel\Monolog\Handler;
134

5+
use Monolog\Formatter\FormatterInterface;
6+
use Monolog\Formatter\LineFormatter;
147
use Monolog\Formatter\NormalizerFormatter;
158
use Monolog\Handler\StreamHandler;
169

@@ -19,7 +12,7 @@
1912
*
2013
* Can be used to store big loads to physical files and import them later into another system that can handle CSV
2114
*
22-
* @author Jay MOULIN <jaymoulin@gmail.com>
15+
* @author Jay MOULIN <jay@femtopixel.com>
2316
*/
2417
class CsvHandler extends StreamHandler
2518
{
@@ -30,7 +23,7 @@ class CsvHandler extends StreamHandler
3023
/**
3124
* @inheritdoc
3225
*/
33-
protected function streamWrite($resource, array $record)
26+
protected function streamWrite($stream, array $record): void
3427
{
3528
if (is_array($record['formatted'])) {
3629
foreach ($record['formatted'] as $key => $info) {
@@ -39,17 +32,20 @@ protected function streamWrite($resource, array $record)
3932
}
4033
}
4134
}
42-
$formated = (array)$record['formatted'];
35+
$formatted = (array)$record['formatted'];
4336
if (version_compare(PHP_VERSION, '5.5.4', '>=') && !defined('HHVM_VERSION')) {
44-
return fputcsv($resource, $formated, static::DELIMITER, static::ENCLOSURE, static::ESCAPE_CHAR);
37+
fputcsv($stream, $formatted, static::DELIMITER, static::ENCLOSURE, static::ESCAPE_CHAR);
38+
return;
4539
}
46-
return fputcsv($resource, $formated, static::DELIMITER, static::ENCLOSURE);
40+
fputcsv($stream, $formatted, static::DELIMITER, static::ENCLOSURE);
4741
}
4842

4943
/**
50-
* @inheritdoc
44+
* Gets the default formatter.
45+
*
46+
* Overwrite this if the LineFormatter is not a good default for your handler.
5147
*/
52-
protected function getDefaultFormatter()
48+
protected function getDefaultFormatter(): FormatterInterface
5349
{
5450
return new NormalizerFormatter();
5551
}
Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
11
<?php
22

3-
/*
4-
* This file is part of the Monolog package.
5-
*
6-
* (c) Jordi Boggiano <j.boggiano@seld.be>
7-
*
8-
* For the full copyright and license information, please view the LICENSE
9-
* file that was distributed with this source code.
10-
*/
11-
123
namespace FemtoPixel\Monolog\Handler;
134

145
use FemtoPixel\Monolog\TestCase;
156
use Monolog\Logger;
7+
use \Monolog\Formatter\NormalizerFormatter;
168

179
class CsvHandlerTest extends TestCase
1810
{
@@ -32,18 +24,10 @@ public function testWriteWithNormalizer()
3224
{
3325
$handle = fopen('php://memory', 'a+');
3426
$handler = new CsvHandler($handle);
35-
$handler->setFormatter($this->getNormalizeFormatter());
27+
$handler->setFormatter(new NormalizerFormatter);
3628
$handler->handle($this->getRecord(Logger::WARNING, 'doesn\'t fail'));
3729
fseek($handle, 0);
38-
$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~";
30+
$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~";
3931
$this->assertSame(1, preg_match($regexp, fread($handle, 100)));
4032
}
41-
42-
/**
43-
* @return \Monolog\Formatter\NormalizerFormatter
44-
*/
45-
protected function getNormalizeFormatter()
46-
{
47-
return $this->getMock('Monolog\\Formatter\\NormalizerFormatter', null);
48-
}
4933
}

tests/Monolog/TestCase.php

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
11
<?php
22

3-
/*
4-
* This file is part of the Monolog package.
5-
*
6-
* (c) Jordi Boggiano <j.boggiano@seld.be>
7-
*
8-
* For the full copyright and license information, please view the LICENSE
9-
* file that was distributed with this source code.
10-
*/
11-
123
namespace FemtoPixel\Monolog;
134

145
use Monolog\Logger;
6+
use Monolog\Formatter\FormatterInterface;
157

16-
class TestCase extends \PHPUnit_Framework_TestCase
8+
class TestCase extends \PHPUnit\Framework\TestCase
179
{
1810
/**
11+
* @param int $level
12+
* @param string $message
13+
* @param array $context
1914
* @return array Record
2015
*/
2116
protected function getRecord($level = Logger::WARNING, $message = 'test', $context = array())
@@ -32,25 +27,11 @@ protected function getRecord($level = Logger::WARNING, $message = 'test', $conte
3227
}
3328

3429
/**
35-
* @return array
36-
*/
37-
protected function getMultipleRecords()
38-
{
39-
return array(
40-
$this->getRecord(Logger::DEBUG, 'debug message 1'),
41-
$this->getRecord(Logger::DEBUG, 'debug message 2'),
42-
$this->getRecord(Logger::INFO, 'information'),
43-
$this->getRecord(Logger::WARNING, 'warning'),
44-
$this->getRecord(Logger::ERROR, 'error'),
45-
);
46-
}
47-
48-
/**
49-
* @return \Monolog\Formatter\FormatterInterface
30+
* @return FormatterInterface
5031
*/
5132
protected function getIdentityFormatter()
5233
{
53-
$formatter = $this->getMock('Monolog\\Formatter\\FormatterInterface');
34+
$formatter = $this->createMock(FormatterInterface::class);
5435
$formatter->expects($this->any())
5536
->method('format')
5637
->will($this->returnCallback(function ($record) { return $record['message']; }));

0 commit comments

Comments
 (0)