ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
MongoDBHandler.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
16
29{
31
32 public function __construct($mongo, $database, $collection, $level = Logger::DEBUG, $bubble = true)
33 {
34 if (!($mongo instanceof \MongoClient || $mongo instanceof \Mongo || $mongo instanceof \MongoDB\Client)) {
35 throw new \InvalidArgumentException('MongoClient, Mongo or MongoDB\Client instance required');
36 }
37
38 $this->mongoCollection = $mongo->selectCollection($database, $collection);
39
40 parent::__construct($level, $bubble);
41 }
42
43 protected function write(array $record)
44 {
45 if ($this->mongoCollection instanceof \MongoDB\Collection) {
46 $this->mongoCollection->insertOne($record["formatted"]);
47 } else {
48 $this->mongoCollection->save($record["formatted"]);
49 }
50 }
51
55 protected function getDefaultFormatter()
56 {
57 return new NormalizerFormatter();
58 }
59}
An exception for terminatinating execution or to throw for unit testing.
Normalizes incoming records to remove objects/resources so it's easier to dump to various targets.
Base Handler class providing the Handler structure.
Logs to a MongoDB database.
__construct($mongo, $database, $collection, $level=Logger::DEBUG, $bubble=true)
write(array $record)
Writes the record down to the log of the implementing handler.
getDefaultFormatter()
Gets the default formatter.FormatterInterface
Monolog log channel.
Definition: Logger.php:28
const DEBUG
Detailed debug information.
Definition: Logger.php:32