1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-08 06:06:40 +02:00
This commit is contained in:
Jordi Boggiano
2015-07-14 10:25:17 +01:00
parent cf6fa57dd4
commit ca1376bd61
20 changed files with 42 additions and 41 deletions

1
.gitignore vendored
View File

@@ -3,3 +3,4 @@ composer.phar
phpunit.xml phpunit.xml
composer.lock composer.lock
.DS_Store .DS_Store
.php_cs.cache

View File

@@ -63,8 +63,8 @@ class BrowserConsoleHandler extends AbstractProcessingHandler
// Check content type // Check content type
foreach (headers_list() as $header) { foreach (headers_list() as $header) {
if (stripos($header, 'content-type:') === 0) { if (stripos($header, 'content-type:') === 0) {
// This handler only works with HTML and javascript outputs // This handler only works with HTML and javascript outputs
// text/javascript is obsolete in favour of application/javascript, but still used // text/javascript is obsolete in favour of application/javascript, but still used
if (stripos($header, 'application/javascript') !== false || stripos($header, 'text/javascript') !== false) { if (stripos($header, 'application/javascript') !== false || stripos($header, 'text/javascript') !== false) {
$htmlTags = false; $htmlTags = false;
} elseif (stripos($header, 'text/html') === false) { } elseif (stripos($header, 'text/html') === false) {

View File

@@ -129,7 +129,7 @@ class ChromePHPHandler extends AbstractProcessingHandler
$json = @json_encode(self::$json); $json = @json_encode(self::$json);
$data = base64_encode(utf8_encode($json)); $data = base64_encode(utf8_encode($json));
if (strlen($data) > 240*1024) { if (strlen($data) > 240 * 1024) {
self::$overflowed = true; self::$overflowed = true;
$record = array( $record = array(

View File

@@ -33,7 +33,6 @@ class Util
{ {
while ($retries--) { while ($retries--) {
if (curl_exec($ch) === false) { if (curl_exec($ch) === false) {
if (false === in_array(curl_errno($ch), self::$retriableErrorCodes, true) || !$retries) { if (false === in_array(curl_errno($ch), self::$retriableErrorCodes, true) || !$retries) {
if ($closeAfterDone) { if ($closeAfterDone) {
curl_close($ch); curl_close($ch);

View File

@@ -215,7 +215,7 @@ class PHPConsoleHandler extends AbstractProcessingHandler
{ {
$tags = null; $tags = null;
if (!empty($record['context'])) { if (!empty($record['context'])) {
$context =& $record['context']; $context = & $record['context'];
foreach ($this->options['debugTagsKeysInContext'] as $key) { foreach ($this->options['debugTagsKeysInContext'] as $key) {
if (!empty($context[$key])) { if (!empty($context[$key])) {
$tags = $context[$key]; $tags = $context[$key];
@@ -240,4 +240,3 @@ class PHPConsoleHandler extends AbstractProcessingHandler
return new LineFormatter('%message%'); return new LineFormatter('%message%');
} }
} }

View File

@@ -167,7 +167,6 @@ class RavenHandler extends AbstractProcessingHandler
if ($previousUserContext !== false) { if ($previousUserContext !== false) {
$this->ravenClient->user_context($previousUserContext); $this->ravenClient->user_context($previousUserContext);
} }
} }
/** /**

View File

@@ -56,8 +56,7 @@ class RedisHandler extends AbstractProcessingHandler
*/ */
protected function write(array $record) protected function write(array $record)
{ {
if ($this->capSize) if ($this->capSize) {
{
$this->writeCapped($record); $this->writeCapped($record);
} else { } else {
$this->redisClient->rpush($this->redisKey, $record["formatted"]); $this->redisClient->rpush($this->redisKey, $record["formatted"]);
@@ -73,7 +72,7 @@ class RedisHandler extends AbstractProcessingHandler
*/ */
protected function writeCapped(array $record) protected function writeCapped(array $record)
{ {
if($this->redisClient instanceof \Redis) { if ($this->redisClient instanceof \Redis) {
$this->redisClient->multi() $this->redisClient->multi()
->rpush($this->redisKey, $record["formatted"]) ->rpush($this->redisKey, $record["formatted"])
->ltrim($this->redisKey, -$this->capSize, -1) ->ltrim($this->redisKey, -$this->capSize, -1)
@@ -81,7 +80,7 @@ class RedisHandler extends AbstractProcessingHandler
} else { } else {
$redisKey = $this->redisKey; $redisKey = $this->redisKey;
$capSize = $this->capSize; $capSize = $this->capSize;
$this->redisClient->transaction(function($tx) use($record, $redisKey, $capSize) { $this->redisClient->transaction(function ($tx) use ($record, $redisKey, $capSize) {
$tx->rpush($redisKey, $record["formatted"]); $tx->rpush($redisKey, $record["formatted"]);
$tx->ltrim($redisKey, -$capSize, -1); $tx->ltrim($redisKey, -$capSize, -1);
}); });

View File

@@ -219,6 +219,7 @@ class SlackHandler extends SocketHandler
if ($this->iconEmoji) { if ($this->iconEmoji) {
$dataArray['icon_emoji'] = ":{$this->iconEmoji}:"; $dataArray['icon_emoji'] = ":{$this->iconEmoji}:";
} }
return $dataArray; return $dataArray;
} }

View File

@@ -190,7 +190,7 @@ class SocketHandler extends AbstractProcessingHandler
protected function streamSetTimeout() protected function streamSetTimeout()
{ {
$seconds = floor($this->timeout); $seconds = floor($this->timeout);
$microseconds = round(($this->timeout - $seconds)*1e6); $microseconds = round(($this->timeout - $seconds) * 1e6);
return stream_set_timeout($this->resource, $seconds, $microseconds); return stream_set_timeout($this->resource, $seconds, $microseconds);
} }

View File

@@ -57,7 +57,7 @@ class SwiftMailerHandler extends MailHandler
$message = null; $message = null;
if ($this->messageTemplate instanceof \Swift_Message) { if ($this->messageTemplate instanceof \Swift_Message) {
$message = clone $this->messageTemplate; $message = clone $this->messageTemplate;
} else if (is_callable($this->messageTemplate)) { } elseif (is_callable($this->messageTemplate)) {
$message = call_user_func($this->messageTemplate, $content, $records); $message = call_user_func($this->messageTemplate, $content, $records);
} }

View File

@@ -11,8 +11,6 @@
namespace Monolog\Handler; namespace Monolog\Handler;
use Monolog\Logger;
/** /**
* Used for testing purposes. * Used for testing purposes.
* *
@@ -28,7 +26,7 @@ use Monolog\Logger;
* @method boolean hasNotice($record) * @method boolean hasNotice($record)
* @method boolean hasInfo($record) * @method boolean hasInfo($record)
* @method boolean hasDebug($record) * @method boolean hasDebug($record)
* *
* @method boolean hasEmergencyRecords() * @method boolean hasEmergencyRecords()
* @method boolean hasAlertRecords() * @method boolean hasAlertRecords()
* @method boolean hasCriticalRecords() * @method boolean hasCriticalRecords()
@@ -37,7 +35,7 @@ use Monolog\Logger;
* @method boolean hasNoticeRecords() * @method boolean hasNoticeRecords()
* @method boolean hasInfoRecords() * @method boolean hasInfoRecords()
* @method boolean hasDebugRecords() * @method boolean hasDebugRecords()
* *
* @method boolean hasEmergencyThatContains($message) * @method boolean hasEmergencyThatContains($message)
* @method boolean hasAlertThatContains($message) * @method boolean hasAlertThatContains($message)
* @method boolean hasCriticalThatContains($message) * @method boolean hasCriticalThatContains($message)
@@ -46,7 +44,7 @@ use Monolog\Logger;
* @method boolean hasNoticeThatContains($message) * @method boolean hasNoticeThatContains($message)
* @method boolean hasInfoThatContains($message) * @method boolean hasInfoThatContains($message)
* @method boolean hasDebugThatContains($message) * @method boolean hasDebugThatContains($message)
* *
* @method boolean hasEmergencyThatMatches($message) * @method boolean hasEmergencyThatMatches($message)
* @method boolean hasAlertThatMatches($message) * @method boolean hasAlertThatMatches($message)
* @method boolean hasCriticalThatMatches($message) * @method boolean hasCriticalThatMatches($message)
@@ -55,7 +53,7 @@ use Monolog\Logger;
* @method boolean hasNoticeThatMatches($message) * @method boolean hasNoticeThatMatches($message)
* @method boolean hasInfoThatMatches($message) * @method boolean hasInfoThatMatches($message)
* @method boolean hasDebugThatMatches($message) * @method boolean hasDebugThatMatches($message)
* *
* @method boolean hasEmergencyThatPasses($message) * @method boolean hasEmergencyThatPasses($message)
* @method boolean hasAlertThatPasses($message) * @method boolean hasAlertThatPasses($message)
* @method boolean hasCriticalThatPasses($message) * @method boolean hasCriticalThatPasses($message)
@@ -86,21 +84,21 @@ class TestHandler extends AbstractProcessingHandler
$record = $record['message']; $record = $record['message'];
} }
return $this->hasRecordThatPasses(function($rec) use ($record) { return $this->hasRecordThatPasses(function ($rec) use ($record) {
return $rec['message'] === $record; return $rec['message'] === $record;
}, $level); }, $level);
} }
public function hasRecordThatContains($message, $level) public function hasRecordThatContains($message, $level)
{ {
return $this->hasRecordThatPasses(function($rec) use ($message) { return $this->hasRecordThatPasses(function ($rec) use ($message) {
return strpos($rec['message'], $message) !== false; return strpos($rec['message'], $message) !== false;
}, $level); }, $level);
} }
public function hasRecordThatMatches($regex, $level) public function hasRecordThatMatches($regex, $level)
{ {
return $this->hasRecordThatPasses(function($rec) use ($regex) { return $this->hasRecordThatPasses(function ($rec) use ($regex) {
return preg_match($regex, $rec['message']) > 0; return preg_match($regex, $rec['message']) > 0;
}, $level); }, $level);
} }
@@ -133,7 +131,6 @@ class TestHandler extends AbstractProcessingHandler
$this->records[] = $record; $this->records[] = $record;
} }
public function __call($method, $args) public function __call($method, $args)
{ {
if (preg_match('/(.*)(Debug|Info|Notice|Warning|Error|Critical|Alert|Emergency)(.*)/', $method, $matches) > 0) { if (preg_match('/(.*)(Debug|Info|Notice|Warning|Error|Critical|Alert|Emergency)(.*)/', $method, $matches) > 0) {
@@ -141,6 +138,7 @@ class TestHandler extends AbstractProcessingHandler
$level = constant('Monolog\Logger::' . strtoupper($matches[2])); $level = constant('Monolog\Logger::' . strtoupper($matches[2]));
if (method_exists($this, $genericMethod)) { if (method_exists($this, $genericMethod)) {
$args[] = $level; $args[] = $level;
return call_user_func_array(array($this, $genericMethod), $args); return call_user_func_array(array($this, $genericMethod), $args);
} }
} }

View File

@@ -157,6 +157,7 @@ class Logger implements LoggerInterface
public function pushHandler(HandlerInterface $handler) public function pushHandler(HandlerInterface $handler)
{ {
array_unshift($this->handlers, $handler); array_unshift($this->handlers, $handler);
return $this; return $this;
} }
@@ -194,6 +195,7 @@ class Logger implements LoggerInterface
throw new \InvalidArgumentException('Processors must be valid callables (callback or object with an __invoke method), '.var_export($callback, true).' given'); throw new \InvalidArgumentException('Processors must be valid callables (callback or object with an __invoke method), '.var_export($callback, true).' given');
} }
array_unshift($this->processors, $callback); array_unshift($this->processors, $callback);
return $this; return $this;
} }

View File

@@ -70,8 +70,8 @@ class IntrospectionProcessor
$record['extra'] = array_merge( $record['extra'] = array_merge(
$record['extra'], $record['extra'],
array( array(
'file' => isset($trace[$i-1]['file']) ? $trace[$i-1]['file'] : null, 'file' => isset($trace[$i - 1]['file']) ? $trace[$i - 1]['file'] : null,
'line' => isset($trace[$i-1]['line']) ? $trace[$i-1]['line'] : null, 'line' => isset($trace[$i - 1]['line']) ? $trace[$i - 1]['line'] : null,
'class' => isset($trace[$i]['class']) ? $trace[$i]['class'] : null, 'class' => isset($trace[$i]['class']) ? $trace[$i]['class'] : null,
'function' => isset($trace[$i]['function']) ? $trace[$i]['function'] : null, 'function' => isset($trace[$i]['function']) ? $trace[$i]['function'] : null,
) )

View File

@@ -52,10 +52,10 @@ abstract class MemoryProcessor
return $bytes; return $bytes;
} }
if ($bytes > 1024*1024) { if ($bytes > 1024 * 1024) {
return round($bytes/1024/1024, 2).' MB'; return round($bytes / 1024 / 1024, 2).' MB';
} elseif ($bytes > 1024) { } elseif ($bytes > 1024) {
return round($bytes/1024, 2).' KB'; return round($bytes / 1024, 2).' KB';
} }
return $bytes . ' B'; return $bytes . ' B';

View File

@@ -120,7 +120,7 @@ class LineFormatterTest extends \PHPUnit_Framework_TestCase
$path = str_replace('\\/', '/', json_encode(__FILE__)); $path = str_replace('\\/', '/', json_encode(__FILE__));
$this->assertEquals('['.date('Y-m-d').'] core.CRITICAL: foobar {"exception":"[object] (RuntimeException(code: 0): Foo at '.substr($path, 1, -1).':'.(__LINE__-8).')"} []'."\n", $message); $this->assertEquals('['.date('Y-m-d').'] core.CRITICAL: foobar {"exception":"[object] (RuntimeException(code: 0): Foo at '.substr($path, 1, -1).':'.(__LINE__ - 8).')"} []'."\n", $message);
} }
public function testDefFormatWithPreviousException() public function testDefFormatWithPreviousException()
@@ -138,7 +138,7 @@ class LineFormatterTest extends \PHPUnit_Framework_TestCase
$path = str_replace('\\/', '/', json_encode(__FILE__)); $path = str_replace('\\/', '/', json_encode(__FILE__));
$this->assertEquals('['.date('Y-m-d').'] core.CRITICAL: foobar {"exception":"[object] (RuntimeException(code: 0): Foo at '.substr($path, 1, -1).':'.(__LINE__-8).', LogicException(code: 0): Wut? at '.substr($path, 1, -1).':'.(__LINE__-12).')"} []'."\n", $message); $this->assertEquals('['.date('Y-m-d').'] core.CRITICAL: foobar {"exception":"[object] (RuntimeException(code: 0): Foo at '.substr($path, 1, -1).':'.(__LINE__ - 8).', LogicException(code: 0): Wut? at '.substr($path, 1, -1).':'.(__LINE__ - 12).')"} []'."\n", $message);
} }
public function testBatchFormat() public function testBatchFormat()

View File

@@ -51,10 +51,10 @@ class ChromePHPHandlerTest extends TestCase
{ {
$handler = new TestChromePHPHandler(); $handler = new TestChromePHPHandler();
$handler->handle($this->getRecord(Logger::DEBUG)); $handler->handle($this->getRecord(Logger::DEBUG));
$handler->handle($this->getRecord(Logger::WARNING, str_repeat('a', 150*1024))); $handler->handle($this->getRecord(Logger::WARNING, str_repeat('a', 150 * 1024)));
// overflow chrome headers limit // overflow chrome headers limit
$handler->handle($this->getRecord(Logger::WARNING, str_repeat('a', 100*1024))); $handler->handle($this->getRecord(Logger::WARNING, str_repeat('a', 100 * 1024)));
$expected = array( $expected = array(
'X-ChromeLogger-Data' => base64_encode(utf8_encode(json_encode(array( 'X-ChromeLogger-Data' => base64_encode(utf8_encode(json_encode(array(
@@ -69,7 +69,7 @@ class ChromePHPHandlerTest extends TestCase
), ),
array( array(
'test', 'test',
str_repeat('a', 150*1024), str_repeat('a', 150 * 1024),
'unknown', 'unknown',
'warn', 'warn',
), ),

View File

@@ -47,7 +47,8 @@ class HipChatHandlerTest extends TestCase
return $content; return $content;
} }
public function testWriteV2() { public function testWriteV2()
{
$this->createHandler('myToken', 'room1', 'Monolog', false, 'hipchat.foo.bar', 'v2'); $this->createHandler('myToken', 'room1', 'Monolog', false, 'hipchat.foo.bar', 'v2');
$this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1')); $this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1'));
fseek($this->res, 0); fseek($this->res, 0);
@@ -58,7 +59,8 @@ class HipChatHandlerTest extends TestCase
return $content; return $content;
} }
public function testWriteV2Notify() { public function testWriteV2Notify()
{
$this->createHandler('myToken', 'room1', 'Monolog', true, 'hipchat.foo.bar', 'v2'); $this->createHandler('myToken', 'room1', 'Monolog', true, 'hipchat.foo.bar', 'v2');
$this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1')); $this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1'));
fseek($this->res, 0); fseek($this->res, 0);
@@ -69,7 +71,8 @@ class HipChatHandlerTest extends TestCase
return $content; return $content;
} }
public function testRoomSpaces() { public function testRoomSpaces()
{
$this->createHandler('myToken', 'room name', 'Monolog', false, 'hipchat.foo.bar', 'v2'); $this->createHandler('myToken', 'room name', 'Monolog', false, 'hipchat.foo.bar', 'v2');
$this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1')); $this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1'));
fseek($this->res, 0); fseek($this->res, 0);
@@ -233,7 +236,8 @@ class HipChatHandlerTest extends TestCase
$hipChatHandler = new \Monolog\Handler\HipChatHandler('token', 'room', 'SixteenCharsHere'); $hipChatHandler = new \Monolog\Handler\HipChatHandler('token', 'room', 'SixteenCharsHere');
} }
public function testCreateWithTooLongNameV2() { public function testCreateWithTooLongNameV2()
{
// creating a handler with too long of a name but using the v2 api doesn't matter. // creating a handler with too long of a name but using the v2 api doesn't matter.
$hipChatHandler = new \Monolog\Handler\HipChatHandler('token', 'room', 'SixteenCharsHere', false, Logger::CRITICAL, true, true, 'test', 'api.hipchat.com', 'v2'); $hipChatHandler = new \Monolog\Handler\HipChatHandler('token', 'room', 'SixteenCharsHere', false, Logger::CRITICAL, true, true, 'test', 'api.hipchat.com', 'v2');
} }

View File

@@ -114,7 +114,7 @@ class RedisHandlerTest extends TestCase
// Redis uses multi // Redis uses multi
$redis->expects($this->once()) $redis->expects($this->once())
->method('transaction') ->method('transaction')
->will($this->returnCallback(function($cb) use ($redisTransaction){ ->will($this->returnCallback(function ($cb) use ($redisTransaction) {
$cb($redisTransaction); $cb($redisTransaction);
})); }));

View File

@@ -28,7 +28,7 @@ class TestHandlerTest extends TestCase
$record = $this->getRecord($level, 'test'.$method); $record = $this->getRecord($level, 'test'.$method);
$this->assertFalse($handler->{'has'.$method}($record), 'has'.$method); $this->assertFalse($handler->{'has'.$method}($record), 'has'.$method);
$this->assertFalse($handler->{'has'.$method.'ThatContains'}('test'), 'has'.$method.'ThatContains'); $this->assertFalse($handler->{'has'.$method.'ThatContains'}('test'), 'has'.$method.'ThatContains');
$this->assertFalse($handler->{'has'.$method.'ThatPasses'}(function($rec){ $this->assertFalse($handler->{'has'.$method.'ThatPasses'}(function ($rec) {
return true; return true;
}), 'has'.$method.'ThatPasses'); }), 'has'.$method.'ThatPasses');
$this->assertFalse($handler->{'has'.$method.'ThatMatches'}('/test\w+/')); $this->assertFalse($handler->{'has'.$method.'ThatMatches'}('/test\w+/'));
@@ -39,7 +39,7 @@ class TestHandlerTest extends TestCase
$this->assertTrue($handler->{'has'.$method}($record), 'has'.$method); $this->assertTrue($handler->{'has'.$method}($record), 'has'.$method);
$this->assertTrue($handler->{'has'.$method}('test'.$method), 'has'.$method); $this->assertTrue($handler->{'has'.$method}('test'.$method), 'has'.$method);
$this->assertTrue($handler->{'has'.$method.'ThatContains'}('test'), 'has'.$method.'ThatContains'); $this->assertTrue($handler->{'has'.$method.'ThatContains'}('test'), 'has'.$method.'ThatContains');
$this->assertTrue($handler->{'has'.$method.'ThatPasses'}(function($rec){ $this->assertTrue($handler->{'has'.$method.'ThatPasses'}(function ($rec) {
return true; return true;
}), 'has'.$method.'ThatPasses'); }), 'has'.$method.'ThatPasses');
$this->assertTrue($handler->{'has'.$method.'ThatMatches'}('/test\w+/')); $this->assertTrue($handler->{'has'.$method.'ThatMatches'}('/test\w+/'));

View File

@@ -11,7 +11,6 @@
namespace Monolog; namespace Monolog;
class RegistryTest extends \PHPUnit_Framework_TestCase class RegistryTest extends \PHPUnit_Framework_TestCase
{ {
protected function setUp() protected function setUp()