1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-05 04:37:38 +02:00

Merge branch '1.x'

This commit is contained in:
Jordi Boggiano
2017-06-19 02:16:33 +02:00
11 changed files with 66 additions and 27 deletions

View File

@@ -24,7 +24,7 @@
"doctrine/couchdb": "~1.0@dev", "doctrine/couchdb": "~1.0@dev",
"aws/aws-sdk-php": "^2.4.9 || ^3.0", "aws/aws-sdk-php": "^2.4.9 || ^3.0",
"php-amqplib/php-amqplib": "~2.4", "php-amqplib/php-amqplib": "~2.4",
"swiftmailer/swiftmailer": "~5.3", "swiftmailer/swiftmailer": "^5.3|^6.0",
"php-console/php-console": "^3.1.3", "php-console/php-console": "^3.1.3",
"jakub-onderka/php-parallel-lint": "^0.9", "jakub-onderka/php-parallel-lint": "^0.9",
"predis/predis": "^1.1", "predis/predis": "^1.1",

View File

@@ -37,7 +37,7 @@ class ChromePHPHandler extends AbstractProcessingHandler
/** /**
* Regular expression to detect supported browsers (matches any Chrome, or Firefox 43+) * Regular expression to detect supported browsers (matches any Chrome, or Firefox 43+)
*/ */
const USER_AGENT_REGEX = '{\b(?:Chrome/\d+(?:\.\d+)*|Firefox/(?:4[3-9]|[5-9]\d|\d{3,})(?:\.\d)*)\b}'; const USER_AGENT_REGEX = '{\b(?:Chrome/\d+(?:\.\d+)*|HeadlessChrome|Firefox/(?:4[3-9]|[5-9]\d|\d{3,})(?:\.\d)*)\b}';
protected static $initialized = false; protected static $initialized = false;

View File

@@ -11,7 +11,7 @@
namespace Monolog\Handler; namespace Monolog\Handler;
use Aws\Common\Aws; use Aws\Sdk;
use Aws\DynamoDb\DynamoDbClient; use Aws\DynamoDb\DynamoDbClient;
use Monolog\Formatter\FormatterInterface; use Monolog\Formatter\FormatterInterface;
use Aws\DynamoDb\Marshaler; use Aws\DynamoDb\Marshaler;
@@ -56,7 +56,7 @@ class DynamoDbHandler extends AbstractProcessingHandler
*/ */
public function __construct(DynamoDbClient $client, $table, $level = Logger::DEBUG, $bubble = true) public function __construct(DynamoDbClient $client, $table, $level = Logger::DEBUG, $bubble = true)
{ {
if (defined('Aws\Common\Aws::VERSION') && version_compare(Aws::VERSION, '3.0', '>=')) { if (defined('Aws\Sdk::VERSION') && version_compare(Sdk::VERSION, '3.0', '>=')) {
$this->version = 3; $this->version = 3;
$this->marshaler = new Marshaler; $this->marshaler = new Marshaler;
} else { } else {

View File

@@ -16,15 +16,17 @@ use Monolog\Formatter\FormatterInterface;
/** /**
* This simple wrapper class can be used to extend handlers functionality. * This simple wrapper class can be used to extend handlers functionality.
* *
* Example: A filtering handle. Inherit from this class, override isHandling() like this * Example: A custom filtering that can be applied to any handler.
* *
* public function isHandling(array $record) * Inherit from this class and override handle() like this:
* { *
* if ($record meets certain conditions) { * public function handle(array $record)
* return false; * {
* } * if ($record meets certain conditions) {
* return $this->handler->isHandling($record); * return false;
* } * }
* return $this->handler->handle($record);
* }
* *
* @author Alexey Karapetov <alexey@karapetov.com> * @author Alexey Karapetov <alexey@karapetov.com>
*/ */

View File

@@ -81,13 +81,18 @@ class SlackWebhookHandler extends AbstractProcessingHandler
$postString = json_encode($postData); $postString = json_encode($postData);
$ch = curl_init(); $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->webhookUrl); $options = [
curl_setopt($ch, CURLOPT_POST, true); CURLOPT_URL => $this->webhookUrl,
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Content-type: application/json'],
CURLOPT_POSTFIELDS => $postString
];
if (defined('CURLOPT_SAFE_UPLOAD')) { if (defined('CURLOPT_SAFE_UPLOAD')) {
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true); $options[CURLOPT_SAFE_UPLOAD] = true;
} }
curl_setopt($ch, CURLOPT_POSTFIELDS, array('payload' => $postString));
curl_setopt_array($ch, $options);
Curl\Util::execute($ch); Curl\Util::execute($ch);
} }

View File

@@ -14,6 +14,7 @@ namespace Monolog\Handler;
use Monolog\Logger; use Monolog\Logger;
use Monolog\Formatter\LineFormatter; use Monolog\Formatter\LineFormatter;
use Swift_Message; use Swift_Message;
use Swift;
/** /**
* SwiftMailerHandler uses Swift_Mailer to send the emails * SwiftMailerHandler uses Swift_Mailer to send the emails
@@ -79,7 +80,11 @@ class SwiftMailerHandler extends MailHandler
} }
$message->setBody($content, $mime); $message->setBody($content, $mime);
$message->setDate(time()); if (version_compare(Swift::VERSION, '6.0.0', '>=')) {
$message->setDate(new \DateTimeImmutable());
} else {
$message->setDate(time());
}
return $message; return $message;
} }

View File

@@ -51,7 +51,12 @@ class IntrospectionProcessor
return $record; return $record;
} }
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); /*
* http://php.net/manual/en/function.debug-backtrace.php
* As of 5.3.6, DEBUG_BACKTRACE_IGNORE_ARGS option was added.
* Any version less than 5.3.6 must use the DEBUG_BACKTRACE_IGNORE_ARGS constant value '2'.
*/
$trace = debug_backtrace((PHP_VERSION_ID < 50306) ? 2 : DEBUG_BACKTRACE_IGNORE_ARGS);
// skip first since it's always the current method // skip first since it's always the current method
array_shift($trace); array_shift($trace);

View File

@@ -25,8 +25,13 @@ class ChromePHPHandlerTest extends TestCase
$_SERVER['HTTP_USER_AGENT'] = 'Monolog Test; Chrome/1.0'; $_SERVER['HTTP_USER_AGENT'] = 'Monolog Test; Chrome/1.0';
} }
public function testHeaders() /**
* @dataProvider agentsProvider
*/
public function testHeaders($agent)
{ {
$_SERVER['HTTP_USER_AGENT'] = $agent;
$handler = new TestChromePHPHandler(); $handler = new TestChromePHPHandler();
$handler->setFormatter($this->getIdentityFormatter()); $handler->setFormatter($this->getIdentityFormatter());
$handler->handle($this->getRecord(Logger::DEBUG)); $handler->handle($this->getRecord(Logger::DEBUG));
@@ -47,6 +52,16 @@ class ChromePHPHandlerTest extends TestCase
$this->assertEquals($expected, $handler->getHeaders()); $this->assertEquals($expected, $handler->getHeaders());
} }
public static function agentsProvider()
{
return array(
array('Monolog Test; Chrome/1.0'),
array('Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0'),
array('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/56.0.2924.76 Chrome/56.0.2924.76 Safari/537.36'),
array('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome Safari/537.36'),
);
}
public function testHeadersOverflow() public function testHeadersOverflow()
{ {
$handler = new TestChromePHPHandler(); $handler = new TestChromePHPHandler();

View File

@@ -53,13 +53,20 @@ class DynamoDbHandlerTest extends TestCase
$handler = new DynamoDbHandler($this->client, 'foo'); $handler = new DynamoDbHandler($this->client, 'foo');
$handler->setFormatter($formatter); $handler->setFormatter($formatter);
$isV3 = defined('Aws\Sdk::VERSION') && version_compare(\Aws\Sdk::VERSION, '3.0', '>=');
if ($isV3) {
$expFormatted = array('foo' => array('N' => 1), 'bar' => array('N' => 2));
} else {
$expFormatted = $formatted;
}
$formatter $formatter
->expects($this->once()) ->expects($this->once())
->method('format') ->method('format')
->with($record) ->with($record)
->will($this->returnValue($formatted)); ->will($this->returnValue($formatted));
$this->client $this->client
->expects($this->once()) ->expects($isV3 ? $this->never() : $this->once())
->method('formatAttributes') ->method('formatAttributes')
->with($this->isType('array')) ->with($this->isType('array'))
->will($this->returnValue($formatted)); ->will($this->returnValue($formatted));
@@ -68,7 +75,7 @@ class DynamoDbHandlerTest extends TestCase
->method('__call') ->method('__call')
->with('putItem', [[ ->with('putItem', [[
'TableName' => 'foo', 'TableName' => 'foo',
'Item' => $formatted, 'Item' => $expFormatted,
]]); ]]);
$handler->handle($record); $handler->handle($record);

View File

@@ -102,11 +102,11 @@ class RotatingFileHandlerTest extends TestCase
$dayCallback = function ($ago) use ($now) { $dayCallback = function ($ago) use ($now) {
return $now + 86400 * $ago; return $now + 86400 * $ago;
}; };
$monthCallback = function ($ago) { $monthCallback = function($ago) {
return gmmktime(0, 0, 0, (int) (date('n') + $ago), (int) date('d'), (int) date('Y')); return gmmktime(0, 0, 0, (int) (date('n') + $ago), 1, (int) date('Y'));
}; };
$yearCallback = function ($ago) { $yearCallback = function($ago) {
return gmmktime(0, 0, 0, (int) date('n'), (int) date('d'), (int) (date('Y') + $ago)); return gmmktime(0, 0, 0, 1, 1, (int) (date('Y') + $ago));
}; };
return [ return [

View File

@@ -99,7 +99,7 @@ class SwiftMailerHandlerTest extends TestCase
public function testMessageHaveUniqueId() public function testMessageHaveUniqueId()
{ {
$messageTemplate = \Swift_Message::newInstance(); $messageTemplate = new \Swift_Message();
$handler = new SwiftMailerHandler($this->mailer, $messageTemplate); $handler = new SwiftMailerHandler($this->mailer, $messageTemplate);
$method = new \ReflectionMethod('Monolog\Handler\SwiftMailerHandler', 'buildMessage'); $method = new \ReflectionMethod('Monolog\Handler\SwiftMailerHandler', 'buildMessage');