ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
12 namespace Monolog\Handler;
13 
14 use Aws\Common\Aws;
17 use Monolog\Logger;
18 
26 {
27  const DATE_FORMAT = 'Y-m-d\TH:i:s.uO';
28 
32  protected $client;
33 
37  protected $table;
38 
45  public function __construct(DynamoDbClient $client, $table, $level = Logger::DEBUG, $bubble = true)
46  {
47  if (!defined('Aws\Common\Aws::VERSION') || version_compare('3.0', Aws::VERSION, '<=')) {
48  throw new \RuntimeException('The DynamoDbHandler is only known to work with the AWS SDK 2.x releases');
49  }
50 
51  $this->client = $client;
52  $this->table = $table;
53 
54  parent::__construct($level, $bubble);
55  }
56 
60  protected function write(array $record)
61  {
62  $filtered = $this->filterEmptyFields($record['formatted']);
63  $formatted = $this->client->formatAttributes($filtered);
64 
65  $this->client->putItem(array(
66  'TableName' => $this->table,
67  'Item' => $formatted,
68  ));
69  }
70 
75  protected function filterEmptyFields(array $record)
76  {
77  return array_filter($record, function ($value) {
78  return !empty($value) || false === $value || 0 === $value;
79  });
80  }
81 
85  protected function getDefaultFormatter()
86  {
87  return new ScalarFormatter(self::DATE_FORMAT);
88  }
89 }
const DEBUG
Detailed debug information.
Definition: Logger.php:32
Base Handler class providing the Handler structure.
Create styles array
The data for the language used.
Formats data into an associative array of scalar values.
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
Definition: bootstrap.php:27
__construct(DynamoDbClient $client, $table, $level=Logger::DEBUG, $bubble=true)
Amazon DynamoDB handler (http://aws.amazon.com/dynamodb/)