mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-05 04:37:38 +02:00
Add support for AWS SDK v3
This commit is contained in:
@@ -22,7 +22,7 @@
|
||||
"sentry/sentry": "^0.13",
|
||||
"ruflin/elastica": ">=0.90 <3.0",
|
||||
"doctrine/couchdb": "~1.0@dev",
|
||||
"aws/aws-sdk-php": "^2.4.9",
|
||||
"aws/aws-sdk-php": "^2.4.9 || ^3.0",
|
||||
"php-amqplib/php-amqplib": "~2.4",
|
||||
"swiftmailer/swiftmailer": "~5.3",
|
||||
"php-console/php-console": "^3.1.3",
|
||||
|
@@ -13,6 +13,7 @@ namespace Monolog\Handler;
|
||||
|
||||
use Aws\Common\Aws;
|
||||
use Aws\DynamoDb\DynamoDbClient;
|
||||
use Aws\DynamoDb\Marshaler;
|
||||
use Monolog\Formatter\ScalarFormatter;
|
||||
use Monolog\Logger;
|
||||
|
||||
@@ -36,6 +37,16 @@ class DynamoDbHandler extends AbstractProcessingHandler
|
||||
*/
|
||||
protected $table;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $version;
|
||||
|
||||
/**
|
||||
* @var Marshaler
|
||||
*/
|
||||
protected $marshaler;
|
||||
|
||||
/**
|
||||
* @param DynamoDbClient $client
|
||||
* @param string $table
|
||||
@@ -44,8 +55,11 @@ class DynamoDbHandler extends AbstractProcessingHandler
|
||||
*/
|
||||
public function __construct(DynamoDbClient $client, $table, $level = Logger::DEBUG, $bubble = true)
|
||||
{
|
||||
if (!defined('Aws\Common\Aws::VERSION') || version_compare('3.0', Aws::VERSION, '<=')) {
|
||||
throw new \RuntimeException('The DynamoDbHandler is only known to work with the AWS SDK 2.x releases');
|
||||
if (defined('Aws\Common\Aws::VERSION') && version_compare(Aws::VERSION, '3.0', '>=')) {
|
||||
$this->version = 3;
|
||||
$this->marshaler = new Marshaler;
|
||||
} else {
|
||||
$this->version = 2;
|
||||
}
|
||||
|
||||
$this->client = $client;
|
||||
@@ -60,7 +74,11 @@ class DynamoDbHandler extends AbstractProcessingHandler
|
||||
protected function write(array $record)
|
||||
{
|
||||
$filtered = $this->filterEmptyFields($record['formatted']);
|
||||
$formatted = $this->client->formatAttributes($filtered);
|
||||
if ($this->version === 3) {
|
||||
$formatted = $this->marshaler->marshalItem($filtered);
|
||||
} else {
|
||||
$formatted = $this->client->formatAttributes($filtered);
|
||||
}
|
||||
|
||||
$this->client->putItem(array(
|
||||
'TableName' => $this->table,
|
||||
|
Reference in New Issue
Block a user