ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
12 namespace Monolog\Handler;
13 
14 use Monolog\Logger;
16 
29 {
30  protected $mongoCollection;
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 }
const DEBUG
Detailed debug information.
Definition: Logger.php:33
Base Handler class providing the Handler structure.
Logs to a MongoDB database.
Normalizes incoming records to remove objects/resources so it&#39;s easier to dump to various targets...
__construct($mongo, $database, $collection, $level=Logger::DEBUG, $bubble=true)