4 * This file is part of the Monolog package.
6 * (c) Jordi Boggiano <j.boggiano@seld.be>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Monolog\Handler;
15 use Aws\DynamoDb\DynamoDbClient;
16 use Aws\DynamoDb\Marshaler;
17 use Monolog\Formatter\ScalarFormatter;
21 * Amazon DynamoDB handler (http://aws.amazon.com/dynamodb/)
23 * @link https://github.com/aws/aws-sdk-php/
24 * @author Andrew Lawson <adlawson@gmail.com>
26 class DynamoDbHandler extends AbstractProcessingHandler
28 const DATE_FORMAT = 'Y-m-d\TH:i:s.uO';
51 * @param DynamoDbClient $client
52 * @param string $table
56 public function __construct(DynamoDbClient $client, $table, $level = Logger::DEBUG, $bubble = true)
58 if (defined('Aws\Common\Aws::VERSION') && version_compare(Aws::VERSION, '3.0', '>=')) {
60 $this->marshaler = new Marshaler;
65 $this->client = $client;
66 $this->table = $table;
68 parent::__construct($level, $bubble);
74 protected function write(array $record)
76 $filtered = $this->filterEmptyFields($record['formatted']);
77 if ($this->version === 3) {
78 $formatted = $this->marshaler->marshalItem($filtered);
80 $formatted = $this->client->formatAttributes($filtered);
83 $this->client->putItem(array(
84 'TableName' => $this->table,
90 * @param array $record
93 protected function filterEmptyFields(array $record)
95 return array_filter($record, function ($value) {
96 return !empty($value) || false === $value || 0 === $value;
103 protected function getDefaultFormatter()
105 return new ScalarFormatter(self::DATE_FORMAT);