ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
DynamoDbHandler.php
Go to the documentation of this file.
1<?php
2
3/*
4 * This file is part of the Monolog package.
5 *
6 * (c) Jordi Boggiano <j.boggiano@seld.be>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Monolog\Handler;
13
14use Aws\Sdk;
15use Aws\DynamoDb\DynamoDbClient;
16use Aws\DynamoDb\Marshaler;
19
27{
28 const DATE_FORMAT = 'Y-m-d\TH:i:s.uO';
29
33 protected $client;
34
38 protected $table;
39
43 protected $version;
44
48 protected $marshaler;
49
56 public function __construct(DynamoDbClient $client, $table, $level = Logger::DEBUG, $bubble = true)
57 {
58 if (defined('Aws\Sdk::VERSION') && version_compare(Sdk::VERSION, '3.0', '>=')) {
59 $this->version = 3;
60 $this->marshaler = new Marshaler;
61 } else {
62 $this->version = 2;
63 }
64
65 $this->client = $client;
66 $this->table = $table;
67
68 parent::__construct($level, $bubble);
69 }
70
74 protected function write(array $record)
75 {
76 $filtered = $this->filterEmptyFields($record['formatted']);
77 if ($this->version === 3) {
78 $formatted = $this->marshaler->marshalItem($filtered);
79 } else {
80 $formatted = $this->client->formatAttributes($filtered);
81 }
82
83 $this->client->putItem(array(
84 'TableName' => $this->table,
85 'Item' => $formatted,
86 ));
87 }
88
93 protected function filterEmptyFields(array $record)
94 {
95 return array_filter($record, function ($value) {
96 return !empty($value) || false === $value || 0 === $value;
97 });
98 }
99
103 protected function getDefaultFormatter()
104 {
105 return new ScalarFormatter(self::DATE_FORMAT);
106 }
107}
An exception for terminatinating execution or to throw for unit testing.
Formats data into an associative array of scalar values.
Base Handler class providing the Handler structure.
Amazon DynamoDB handler (http://aws.amazon.com/dynamodb/)
getDefaultFormatter()
{Gets the default formatter.FormatterInterface}
__construct(DynamoDbClient $client, $table, $level=Logger::DEBUG, $bubble=true)
write(array $record)
{Writes the record down to the log of the implementing handler.void}
Monolog log channel.
Definition: Logger.php:29
const DEBUG
Detailed debug information.
Definition: Logger.php:33