1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-04 04:07:39 +02:00
This commit is contained in:
Jordi Boggiano
2014-03-23 20:50:26 +01:00
parent 8222de98a4
commit 392ef35fd4
29 changed files with 55 additions and 88 deletions

View File

@@ -95,7 +95,7 @@ class JsonFormatter implements FormatterInterface
{ {
$instance = $this; $instance = $this;
array_walk($records, function(&$value, $key) use ($instance) { array_walk($records, function (&$value, $key) use ($instance) {
$value = $instance->format($value); $value = $instance->format($value);
}); });

View File

@@ -42,6 +42,7 @@ class LogglyFormatter extends JsonFormatter
$record["timestamp"] = $record["datetime"]->format("c"); $record["timestamp"] = $record["datetime"]->format("c");
// @todo unset the 'datetime' parameter, retained for BC // @todo unset the 'datetime' parameter, retained for BC
} }
return parent::format($record); return parent::format($record);
} }

View File

@@ -11,7 +11,6 @@
namespace Monolog\Handler; namespace Monolog\Handler;
use Monolog\Logger;
use Monolog\Formatter\LineFormatter; use Monolog\Formatter\LineFormatter;
/** /**
@@ -103,7 +102,8 @@ class BrowserConsoleHandler extends AbstractProcessingHandler
); );
} }
} }
return "(function(c){if (c && c.groupCollapsed) {\n" . implode("\n", $script) . "\n}})(console);";
return "(function (c) {if (c && c.groupCollapsed) {\n" . implode("\n", $script) . "\n}})(console);";
} }
private static function handleStyles($formatted) private static function handleStyles($formatted)
@@ -130,7 +130,7 @@ class BrowserConsoleHandler extends AbstractProcessingHandler
static $colors = array('blue', 'green', 'red', 'magenta', 'orange', 'black', 'grey'); static $colors = array('blue', 'green', 'red', 'magenta', 'orange', 'black', 'grey');
static $labels = array(); static $labels = array();
return preg_replace_callback('/macro\s*:(.*?)(?:;|$)/', function($m) use($string, &$colors, &$labels) { return preg_replace_callback('/macro\s*:(.*?)(?:;|$)/', function ($m) use ($string, &$colors, &$labels) {
if (trim($m[1]) === 'autolabel') { if (trim($m[1]) === 'autolabel') {
// Format the string as a label with consistent auto assigned background color // Format the string as a label with consistent auto assigned background color
if (!isset($labels[$string])) { if (!isset($labels[$string])) {
@@ -160,6 +160,7 @@ class BrowserConsoleHandler extends AbstractProcessingHandler
} }
$script[] = self::call('log', self::quote('%s: %o'), self::quote($key), $value); $script[] = self::call('log', self::quote('%s: %o'), self::quote($key), $value);
} }
return $script; return $script;
} }
@@ -172,6 +173,7 @@ class BrowserConsoleHandler extends AbstractProcessingHandler
{ {
$args = func_get_args(); $args = func_get_args();
$method = array_shift($args); $method = array_shift($args);
return self::call_array($method, $args); return self::call_array($method, $args);
} }

View File

@@ -14,7 +14,6 @@ namespace Monolog\Handler;
use Aws\Common\Aws; use Aws\Common\Aws;
use Aws\DynamoDb\DynamoDbClient; use Aws\DynamoDb\DynamoDbClient;
use Monolog\Formatter\ScalarFormatter; use Monolog\Formatter\ScalarFormatter;
use Monolog\Handler\AbstractProcessingHandler;
use Monolog\Logger; use Monolog\Logger;
/** /**

View File

@@ -130,6 +130,7 @@ class NativeMailerHandler extends MailHandler
public function setContentType($contentType) public function setContentType($contentType)
{ {
$this->contentType = $contentType; $this->contentType = $contentType;
return $this; return $this;
} }
@@ -140,6 +141,7 @@ class NativeMailerHandler extends MailHandler
public function setEncoding($encoding) public function setEncoding($encoding)
{ {
$this->encoding = $encoding; $this->encoding = $encoding;
return $this; return $this;
} }
} }

View File

@@ -14,7 +14,6 @@ namespace Monolog\Handler;
use Monolog\Formatter\LineFormatter; use Monolog\Formatter\LineFormatter;
use Monolog\Formatter\FormatterInterface; use Monolog\Formatter\FormatterInterface;
use Monolog\Logger; use Monolog\Logger;
use Monolog\Handler\AbstractProcessingHandler;
use Raven_Client; use Raven_Client;
/** /**

View File

@@ -12,7 +12,6 @@
namespace Monolog\Formatter; namespace Monolog\Formatter;
use Monolog\Logger; use Monolog\Logger;
use Monolog\Formatter\ElasticaFormatter;
class ElasticaFormatterTest extends \PHPUnit_Framework_TestCase class ElasticaFormatterTest extends \PHPUnit_Framework_TestCase
{ {

View File

@@ -12,7 +12,6 @@
namespace Monolog\Formatter; namespace Monolog\Formatter;
use Monolog\Logger; use Monolog\Logger;
use Monolog\Formatter\GelfMessageFormatter;
class GelfMessageFormatterTest extends \PHPUnit_Framework_TestCase class GelfMessageFormatterTest extends \PHPUnit_Framework_TestCase
{ {

View File

@@ -64,7 +64,7 @@ class JsonFormatterTest extends TestCase
$this->getRecord(Logger::WARNING), $this->getRecord(Logger::WARNING),
$this->getRecord(Logger::DEBUG), $this->getRecord(Logger::DEBUG),
); );
array_walk($expected, function(&$value, $key) { array_walk($expected, function (&$value, $key) {
$value = json_encode($value); $value = json_encode($value);
}); });
$this->assertEquals(implode("\n", $expected), $formatter->formatBatch($records)); $this->assertEquals(implode("\n", $expected), $formatter->formatBatch($records));

View File

@@ -11,7 +11,6 @@
namespace Monolog\Formatter; namespace Monolog\Formatter;
use Monolog\Logger;
use Monolog\TestCase; use Monolog\TestCase;
class LogglyFormatterTest extends TestCase class LogglyFormatterTest extends TestCase

View File

@@ -12,7 +12,6 @@
namespace Monolog\Formatter; namespace Monolog\Formatter;
use Monolog\Logger; use Monolog\Logger;
use Monolog\Formatter\LogstashFormatter;
class LogstashFormatterTest extends \PHPUnit_Framework_TestCase class LogstashFormatterTest extends \PHPUnit_Framework_TestCase
{ {

View File

@@ -9,7 +9,7 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
spl_autoload_register(function($class) { spl_autoload_register(function ($class) {
$file = __DIR__.'/../../../../src/'.strtr($class, '\\', '/').'.php'; $file = __DIR__.'/../../../../src/'.strtr($class, '\\', '/').'.php';
if (file_exists($file)) { if (file_exists($file)) {
require $file; require $file;

View File

@@ -70,7 +70,7 @@ class AbstractProcessingHandlerTest extends TestCase
$handledRecord = null; $handledRecord = null;
$handler->expects($this->once()) $handler->expects($this->once())
->method('write') ->method('write')
->will($this->returnCallback(function($record) use (&$handledRecord) { ->will($this->returnCallback(function ($record) use (&$handledRecord) {
$handledRecord = $record; $handledRecord = $record;
})) }))
; ;

View File

@@ -40,7 +40,7 @@ class BrowserConsoleHandlerTest extends TestCase
$handler->handle($this->getRecord(Logger::DEBUG, 'foo[[bar]]{color: red}')); $handler->handle($this->getRecord(Logger::DEBUG, 'foo[[bar]]{color: red}'));
$expected = <<<EOF $expected = <<<EOF
(function(c){if (c && c.groupCollapsed) { (function (c) {if (c && c.groupCollapsed) {
c.log("%cfoo%cbar%c", "font-weight: normal", "color: red", "font-weight: normal"); c.log("%cfoo%cbar%c", "font-weight: normal", "color: red", "font-weight: normal");
}})(console); }})(console);
EOF; EOF;
@@ -56,7 +56,7 @@ EOF;
$handler->handle($this->getRecord(Logger::DEBUG, "[foo] [[\"bar\n[baz]\"]]{color: red}")); $handler->handle($this->getRecord(Logger::DEBUG, "[foo] [[\"bar\n[baz]\"]]{color: red}"));
$expected = <<<EOF $expected = <<<EOF
(function(c){if (c && c.groupCollapsed) { (function (c) {if (c && c.groupCollapsed) {
c.log("%c[foo] %c\"bar\\n[baz]\"%c", "font-weight: normal", "color: red", "font-weight: normal"); c.log("%c[foo] %c\"bar\\n[baz]\"%c", "font-weight: normal", "color: red", "font-weight: normal");
}})(console); }})(console);
EOF; EOF;
@@ -75,7 +75,7 @@ EOF;
$handler->handle($this->getRecord(Logger::DEBUG, '[[foo]]{macro: autolabel}')); $handler->handle($this->getRecord(Logger::DEBUG, '[[foo]]{macro: autolabel}'));
$expected = <<<EOF $expected = <<<EOF
(function(c){if (c && c.groupCollapsed) { (function (c) {if (c && c.groupCollapsed) {
c.log("%c%cfoo%c", "font-weight: normal", "background-color: blue; color: white; border-radius: 3px; padding: 0 2px 0 2px", "font-weight: normal"); c.log("%c%cfoo%c", "font-weight: normal", "background-color: blue; color: white; border-radius: 3px; padding: 0 2px 0 2px", "font-weight: normal");
c.log("%c%cbar%c", "font-weight: normal", "background-color: green; color: white; border-radius: 3px; padding: 0 2px 0 2px", "font-weight: normal"); c.log("%c%cbar%c", "font-weight: normal", "background-color: green; color: white; border-radius: 3px; padding: 0 2px 0 2px", "font-weight: normal");
c.log("%c%cfoo%c", "font-weight: normal", "background-color: blue; color: white; border-radius: 3px; padding: 0 2px 0 2px", "font-weight: normal"); c.log("%c%cfoo%c", "font-weight: normal", "background-color: blue; color: white; border-radius: 3px; padding: 0 2px 0 2px", "font-weight: normal");
@@ -93,7 +93,7 @@ EOF;
$handler->handle($this->getRecord(Logger::DEBUG, 'test', array('foo' => 'bar'))); $handler->handle($this->getRecord(Logger::DEBUG, 'test', array('foo' => 'bar')));
$expected = <<<EOF $expected = <<<EOF
(function(c){if (c && c.groupCollapsed) { (function (c) {if (c && c.groupCollapsed) {
c.groupCollapsed("%ctest", "font-weight: normal"); c.groupCollapsed("%ctest", "font-weight: normal");
c.log("%c%s", "font-weight: bold", "Context"); c.log("%c%s", "font-weight: bold", "Context");
c.log("%s: %o", "foo", "bar"); c.log("%s: %o", "foo", "bar");
@@ -118,7 +118,7 @@ EOF;
$handler2->handle($this->getRecord(Logger::DEBUG, 'test4')); $handler2->handle($this->getRecord(Logger::DEBUG, 'test4'));
$expected = <<<EOF $expected = <<<EOF
(function(c){if (c && c.groupCollapsed) { (function (c) {if (c && c.groupCollapsed) {
c.log("%ctest1", "font-weight: normal"); c.log("%ctest1", "font-weight: normal");
c.log("%ctest2", "font-weight: normal"); c.log("%ctest2", "font-weight: normal");
c.log("%ctest3", "font-weight: normal"); c.log("%ctest3", "font-weight: normal");

View File

@@ -11,7 +11,6 @@
namespace Monolog\Handler; namespace Monolog\Handler;
use Monolog\Handler\ElasticSearchHandler;
use Monolog\Formatter\ElasticaFormatter; use Monolog\Formatter\ElasticaFormatter;
use Monolog\Formatter\NormalizerFormatter; use Monolog\Formatter\NormalizerFormatter;
use Monolog\TestCase; use Monolog\TestCase;
@@ -185,7 +184,7 @@ class ElasticSearchHandlerTest extends TestCase
$handler = new ElasticSearchHandler($client, $this->options); $handler = new ElasticSearchHandler($client, $this->options);
try { try {
$handler->handleBatch(array($msg)); $handler->handleBatch(array($msg));
} catch(\RuntimeException $e) { } catch (\RuntimeException $e) {
$this->markTestSkipped("Cannot connect to Elastic Search server on localhost"); $this->markTestSkipped("Cannot connect to Elastic Search server on localhost");
} }
@@ -234,6 +233,7 @@ class ElasticSearchHandlerTest extends TestCase
if (!empty($data['_source'])) { if (!empty($data['_source'])) {
return $data['_source']; return $data['_source'];
} }
return array(); return array();
} }
} }

View File

@@ -102,7 +102,7 @@ class FingersCrossedHandlerTest extends TestCase
public function testHandleWithCallback() public function testHandleWithCallback()
{ {
$test = new TestHandler(); $test = new TestHandler();
$handler = new FingersCrossedHandler(function($record, $handler) use ($test) { $handler = new FingersCrossedHandler(function ($record, $handler) use ($test) {
return $test; return $test;
}); });
$handler->handle($this->getRecord(Logger::DEBUG)); $handler->handle($this->getRecord(Logger::DEBUG));
@@ -120,7 +120,7 @@ class FingersCrossedHandlerTest extends TestCase
*/ */
public function testHandleWithBadCallbackThrowsException() public function testHandleWithBadCallbackThrowsException()
{ {
$handler = new FingersCrossedHandler(function($record, $handler) { $handler = new FingersCrossedHandler(function ($record, $handler) {
return 'foo'; return 'foo';
}); });
$handler->handle($this->getRecord(Logger::WARNING)); $handler->handle($this->getRecord(Logger::WARNING));

View File

@@ -23,8 +23,6 @@ class GelfHandlerLegacyTest extends TestCase
if (!class_exists('Gelf\MessagePublisher') || !class_exists('Gelf\Message')) { if (!class_exists('Gelf\MessagePublisher') || !class_exists('Gelf\Message')) {
$this->markTestSkipped("mlehner/gelf-php not installed"); $this->markTestSkipped("mlehner/gelf-php not installed");
} }
require_once __DIR__ . '/GelfMocks.php';
} }
/** /**

View File

@@ -64,7 +64,6 @@ class GelfHandlerTest extends TestCase
$handler = $this->getHandler($messagePublisher); $handler = $this->getHandler($messagePublisher);
$handler->handle($record); $handler->handle($record);
} }
@@ -87,7 +86,6 @@ class GelfHandlerTest extends TestCase
$handler = $this->getHandler($messagePublisher); $handler = $this->getHandler($messagePublisher);
$handler->handle($record); $handler->handle($record);
} }

View File

@@ -1,25 +0,0 @@
<?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\Handler;
use Gelf\MessagePublisher;
use Gelf\Message;
class MockMessagePublisher extends MessagePublisher
{
public function publish(Message $message)
{
$this->lastMessage = $message;
}
public $lastMessage = null;
}

View File

@@ -14,7 +14,6 @@ namespace Monolog\Handler;
use Monolog\TestCase; use Monolog\TestCase;
use Monolog\Logger; use Monolog\Logger;
use Monolog\Formatter\LineFormatter; use Monolog\Formatter\LineFormatter;
use Monolog\Handler\RavenHandler;
class RavenHandlerTest extends TestCase class RavenHandlerTest extends TestCase
{ {
@@ -99,7 +98,7 @@ class RavenHandlerTest extends TestCase
$logFormatter->expects($this->once())->method('formatBatch'); $logFormatter->expects($this->once())->method('formatBatch');
$formatter = $this->getMock('Monolog\\Formatter\\FormatterInterface'); $formatter = $this->getMock('Monolog\\Formatter\\FormatterInterface');
$formatter->expects($this->once())->method('format')->with($this->callback(function($record) { $formatter->expects($this->once())->method('format')->with($this->callback(function ($record) {
return $record['level'] == 400; return $record['level'] == 400;
})); }));

View File

@@ -120,7 +120,7 @@ class SocketHandlerTest extends TestCase
{ {
$this->setMockHandler(array('fwrite')); $this->setMockHandler(array('fwrite'));
$callback = function($arg) { $callback = function ($arg) {
$map = array( $map = array(
'Hello world' => 6, 'Hello world' => 6,
'world' => false, 'world' => false,
@@ -143,7 +143,7 @@ class SocketHandlerTest extends TestCase
{ {
$this->setMockHandler(array('fwrite', 'streamGetMetadata')); $this->setMockHandler(array('fwrite', 'streamGetMetadata'));
$callback = function($arg) { $callback = function ($arg) {
$map = array( $map = array(
'Hello world' => 6, 'Hello world' => 6,
'world' => 5, 'world' => 5,
@@ -170,7 +170,7 @@ class SocketHandlerTest extends TestCase
$this->setMockHandler(array('fwrite', 'streamGetMetadata')); $this->setMockHandler(array('fwrite', 'streamGetMetadata'));
$res = $this->res; $res = $this->res;
$callback = function($string) use ($res) { $callback = function ($string) use ($res) {
fclose($res); fclose($res);
return strlen('Hello'); return strlen('Hello');
@@ -200,7 +200,7 @@ class SocketHandlerTest extends TestCase
{ {
$this->setMockHandler(array('fwrite')); $this->setMockHandler(array('fwrite'));
$callback = function($arg) { $callback = function ($arg) {
$map = array( $map = array(
'Hello world' => 6, 'Hello world' => 6,
'world' => 5, 'world' => 5,

View File

@@ -2,8 +2,6 @@
namespace Monolog\Handler; namespace Monolog\Handler;
use Monolog\TestCase;
class SyslogUdpHandlerTest extends \PHPUnit_Framework_TestCase class SyslogUdpHandlerTest extends \PHPUnit_Framework_TestCase
{ {
/** /**

View File

@@ -162,7 +162,7 @@ class LoggerTest extends \PHPUnit_Framework_TestCase
$logger = new Logger(__METHOD__); $logger = new Logger(__METHOD__);
$handler = new TestHandler; $handler = new TestHandler;
$logger->pushHandler($handler); $logger->pushHandler($handler);
$logger->pushProcessor(function($record) { $logger->pushProcessor(function ($record) {
$record['extra']['win'] = true; $record['extra']['win'] = true;
return $record; return $record;
@@ -216,7 +216,7 @@ class LoggerTest extends \PHPUnit_Framework_TestCase
; ;
$logger->pushHandler($handler); $logger->pushHandler($handler);
$that = $this; $that = $this;
$logger->pushProcessor(function($record) use ($that) { $logger->pushProcessor(function ($record) use ($that) {
$that->fail('The processor should not be called'); $that->fail('The processor should not be called');
}); });
$logger->addAlert('test'); $logger->addAlert('test');

View File

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