From 435ddc2ec6547edce5de09d92fc7de4f3b37ffe7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Boris=20Mom=C4=8Dilovi=C4=87?= Date: Tue, 3 Nov 2015 20:34:57 +0100 Subject: [PATCH 1/3] MongoDBHandler: support for MongoDB\Client --- src/Monolog/Handler/MongoDBHandler.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Monolog/Handler/MongoDBHandler.php b/src/Monolog/Handler/MongoDBHandler.php index 6c431f2b..84dbdda3 100644 --- a/src/Monolog/Handler/MongoDBHandler.php +++ b/src/Monolog/Handler/MongoDBHandler.php @@ -31,8 +31,8 @@ class MongoDBHandler extends AbstractProcessingHandler public function __construct($mongo, $database, $collection, $level = Logger::DEBUG, $bubble = true) { - if (!($mongo instanceof \MongoClient || $mongo instanceof \Mongo)) { - throw new \InvalidArgumentException('MongoClient or Mongo instance required'); + if (!($mongo instanceof \MongoClient || $mongo instanceof \Mongo || $mongo instanceof \MongoDB\Client)) { + throw new \InvalidArgumentException('MongoClient, Mongo or MongoDB\Client instance required'); } $this->mongoCollection = $mongo->selectCollection($database, $collection); From e099fce1507b8b2acb529331e6a406856a3947be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Boris=20Mom=C4=8Dilovi=C4=87?= Date: Tue, 3 Nov 2015 20:36:15 +0100 Subject: [PATCH 2/3] composer.json: suggest mongodb/mongodb - MongoDB driver library --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index 2bb90535..dafdff28 100644 --- a/composer.json +++ b/composer.json @@ -38,6 +38,7 @@ "videlalvaro/php-amqplib": "Allow sending log messages to an AMQP server using php-amqplib", "ext-amqp": "Allow sending log messages to an AMQP server (1.0+ required)", "ext-mongo": "Allow sending log messages to a MongoDB server", + "mongodb/mongodb": "Allow sending log messages to a MongoDB server via PHP Driver", "aws/aws-sdk-php": "Allow sending log messages to AWS services like DynamoDB", "rollbar/rollbar": "Allow sending log messages to Rollbar", "php-console/php-console": "Allow sending log messages to Google Chrome" From 4764052a102a0e9312f1df345703207d86a5ce1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Boris=20Mom=C4=8Dilovi=C4=87?= Date: Tue, 3 Nov 2015 20:47:58 +0100 Subject: [PATCH 3/3] MongoDBHandler: write: call proper method if we've got instance of MongoDB\Collection --- src/Monolog/Handler/MongoDBHandler.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Monolog/Handler/MongoDBHandler.php b/src/Monolog/Handler/MongoDBHandler.php index 84dbdda3..56fe755b 100644 --- a/src/Monolog/Handler/MongoDBHandler.php +++ b/src/Monolog/Handler/MongoDBHandler.php @@ -42,7 +42,11 @@ class MongoDBHandler extends AbstractProcessingHandler protected function write(array $record) { - $this->mongoCollection->save($record["formatted"]); + if ($this->mongoCollection instanceof \MongoDB\Collection) { + $this->mongoCollection->insertOne($record["formatted"]); + } else { + $this->mongoCollection->save($record["formatted"]); + } } /**