Skip to content

Commit d01ac97

Browse files
committed
update documentation
1 parent f90803c commit d01ac97

File tree

7 files changed

+94
-20
lines changed

7 files changed

+94
-20
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
vendor
2+
build
23
composer.phar
34
phpunit.xml
45
composer.lock
56
.DS_Store
6-
.php_cs.cache

README.mdown

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# CsvHandler for Monolog - Logging for PHP [![Build Status](https://img.shields.io/travis/femtopixel/monolog-csvhandler.svg)](https://travis-ci.org/femtopixel/monolog-csvhandler)
22

3-
[![Total Downloads](https://img.shields.io/packagist/dt/femtopixel/monolog-csvhandler.svg)](https://packagist.org/packages/femtopixel/monolog-csvhandler)
43
[![Latest Stable Version](https://img.shields.io/packagist/v/femtopixel/monolog-csvhandler.svg)](https://packagist.org/packages/femtopixel/monolog-csvhandler)
5-
[![Reference Status](https://www.versioneye.com/php/monolog:monolog/reference_badge.svg)](https://www.versioneye.com/php/monolog:monolog/references)
64

75
CsvHandler for Monolog sends your logs to CSV files. For more information on Monolog, see http://github.com/Seldaek/monolog
86

@@ -24,7 +22,7 @@ use FemtoPixel\Monolog\Handler\CsvHandler;
2422

2523
// create a log channel
2624
$log = new Logger('name');
27-
$log->pushHandler(new SCsvHandler('path/to/your.csv', Logger::WARNING));
25+
$log->pushHandler(new CsvHandler('path/to/your.csv', Logger::WARNING));
2826

2927
// add records to the log
3028
$log->addWarning('Foo');

composer.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,17 @@
1212
"homepage": "http://github.com/jaymoulin"
1313
}
1414
],
15+
"support": {
16+
"issues": "http://github.com/femtopixel/monolog-csvhandler/issues",
17+
"source": "https://github.com/femtopixel/monolog-csvhandler"
18+
},
1519
"require": {
1620
"php": ">=5.3.0",
17-
"monolog/monolog": "^1.21.0",
21+
"monolog/monolog": "1.x-dev",
1822
"psr/log": "~1.0"
1923
},
2024
"require-dev": {
21-
"phpunit/phpunit": "~4.5 || ^5.0"
25+
"phpunit/phpunit": "~4.5"
2226
},
2327
"_": "phpunit/phpunit-mock-objects required in 2.3.0 due to https://github.com/sebastianbergmann/phpunit-mock-objects/issues/223 - needs hhvm 3.8+ on travis",
2428
"autoload": {

phpunit.xml.dist

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,24 @@
33
<phpunit bootstrap="vendor/autoload.php" colors="true">
44
<testsuites>
55
<testsuite name="Monolog Test Suite">
6-
<directory>tests/Monolog/</directory>
6+
<directory>tests</directory>
7+
<directory>tests/*</directory>
78
</testsuite>
89
</testsuites>
910

11+
<logging>
12+
<log type="coverage-html" target="build/coverage/report" lowUpperBound="35" highLowerBound="70"/>
13+
<log type="junit" target="build/logs/junit.xml" />
14+
<log type="coverage-clover" target="build/logs/clover.xml"/>
15+
</logging>
16+
1017
<filter>
1118
<whitelist>
12-
<directory suffix=".php">src/Monolog/</directory>
19+
<directory suffix=".php">src</directory>
1320
</whitelist>
1421
</filter>
1522

1623
<php>
1724
<ini name="date.timezone" value="UTC"/>
1825
</php>
19-
</phpunit>
26+
</phpunit>

src/Monolog/Handler/CsvHandler.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,20 @@ class CsvHandler extends StreamHandler
3030
/**
3131
* @inheritdoc
3232
*/
33-
protected function streamWrite($resource, $record)
33+
protected function streamWrite($resource, array $record)
3434
{
35-
return fputcsv($resource, (array)$record['formatted'], static::DELIMITER, static::ENCLOSURE, static::ESCAPE_CHAR);
35+
if (is_array($record['formatted'])) {
36+
foreach ($record['formatted'] as $key => $info) {
37+
if (is_array($info)) {
38+
$record['formatted'][$key] = json_encode($info);
39+
}
40+
}
41+
}
42+
$formated = (array) $record['formatted'];
43+
if (version_compare(PHP_VERSION, '5.5.4', '>=')) {
44+
return fputcsv($resource, $formated, static::DELIMITER, static::ENCLOSURE, static::ESCAPE_CHAR);
45+
}
46+
return fputcsv($resource, $formated, static::DELIMITER, static::ENCLOSURE);
3647
}
3748

3849
/**

tests/Monolog/Handler/CsvHandlerTest.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,13 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Femtopixel\Monolog\Handler;
12+
namespace FemtoPixel\Monolog\Handler;
1313

14-
use Monolog\TestCase;
14+
use FemtoPixel\Monolog\TestCase;
1515
use Monolog\Logger;
1616

1717
class CsvHandlerTest extends TestCase
1818
{
19-
/**
20-
* @covers CsvHandler::write
21-
*/
2219
public function testWrite()
2320
{
2421
$handle = fopen('php://memory', 'a+');
@@ -31,17 +28,14 @@ public function testWrite()
3128
$this->assertEquals("test\ntest2\ntest3\n", fread($handle, 100));
3229
}
3330

34-
/**
35-
* @covers CsvHandler::write
36-
*/
3731
public function testWriteWithNormalizer()
3832
{
3933
$handle = fopen('php://memory', 'a+');
4034
$handler = new CsvHandler($handle);
4135
$handler->setFormatter($this->getNormalizeFormatter());
4236
$handler->handle($this->getRecord(Logger::WARNING, 'doesn\'t fail'));
4337
fseek($handle, 0);
44-
$regexp = "~\\A'doesn''t fail',Array,300,WARNING,test,'[0-9]{4}\\-[0-9]{2}+\\-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}',Array\n\\Z~";
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~";
4539
$this->assertSame(1, preg_match($regexp, fread($handle, 100)));
4640
}
4741

tests/Monolog/TestCase.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
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+
12+
namespace FemtoPixel\Monolog;
13+
14+
use Monolog\Logger;
15+
16+
class TestCase extends \PHPUnit_Framework_TestCase
17+
{
18+
/**
19+
* @return array Record
20+
*/
21+
protected function getRecord($level = Logger::WARNING, $message = 'test', $context = array())
22+
{
23+
return array(
24+
'message' => $message,
25+
'context' => $context,
26+
'level' => $level,
27+
'level_name' => Logger::getLevelName($level),
28+
'channel' => 'test',
29+
'datetime' => \DateTime::createFromFormat('U.u', sprintf('%.6F', microtime(true))),
30+
'extra' => array(),
31+
);
32+
}
33+
34+
/**
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
50+
*/
51+
protected function getIdentityFormatter()
52+
{
53+
$formatter = $this->getMock('Monolog\\Formatter\\FormatterInterface');
54+
$formatter->expects($this->any())
55+
->method('format')
56+
->will($this->returnCallback(function ($record) { return $record['message']; }));
57+
58+
return $formatter;
59+
}
60+
}

0 commit comments

Comments
 (0)