1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-10-24 10:06:08 +02:00

Merge pull request #676 from kornrunner/master

mongodb/mongodb support
This commit is contained in:
Jordi Boggiano
2015-11-18 17:18:56 +00:00
2 changed files with 8 additions and 3 deletions

View File

@@ -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"

View File

@@ -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);
@@ -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"]);
}
}
/**