mirror of
https://github.com/Seldaek/monolog.git
synced 2025-10-22 00:56:08 +02:00
Add case for if manager is passed in
This commit is contained in:
@@ -28,14 +28,20 @@ use Monolog\Formatter\NormalizerFormatter;
|
||||
class MongoDBHandler extends AbstractProcessingHandler
|
||||
{
|
||||
protected $mongoCollection;
|
||||
protected $namespace;
|
||||
protected $manager;
|
||||
|
||||
public function __construct($mongo, $database, $collection, $level = Logger::DEBUG, $bubble = true)
|
||||
{
|
||||
if (!($mongo instanceof \MongoClient || $mongo instanceof \Mongo || $mongo instanceof \MongoDB\Client)) {
|
||||
if (!($mongo instanceof \MongoClient || $mongo instanceof \Mongo || $mongo instanceof \MongoDB\Client || $mongo instanceof \MongoDB\Driver\Manager)) {
|
||||
throw new \InvalidArgumentException('MongoClient, Mongo or MongoDB\Client instance required');
|
||||
}
|
||||
|
||||
$this->mongoCollection = $mongo->selectCollection($database, $collection);
|
||||
$this->namespace = "$database.$collection";
|
||||
if($mongo instanceof \MongoDB\Driver\Manger) {
|
||||
$this->manager = $mongo;
|
||||
} else {
|
||||
$this->mongoCollection = $mongo->selectCollection($database, $collection);
|
||||
}
|
||||
|
||||
parent::__construct($level, $bubble);
|
||||
}
|
||||
@@ -44,8 +50,12 @@ class MongoDBHandler extends AbstractProcessingHandler
|
||||
{
|
||||
if ($this->mongoCollection instanceof \MongoDB\Collection) {
|
||||
$this->mongoCollection->insertOne($record["formatted"]);
|
||||
} else {
|
||||
} else if($this->mongoCollection instanceof \MongoCollection) {
|
||||
$this->mongoCollection->insert($record["formatted"]);
|
||||
} else {
|
||||
$bulk = new \MongoDB\Driver\BulkWrite();
|
||||
$bulk->insert($record["formatted"]);
|
||||
$this->$manager->executeBulkWrite($this->namespace, $bulk);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user