mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-08 06:06:40 +02:00
Merge remote-tracking branch 'armetiz/master'
This commit is contained in:
42
src/Monolog/Handler/MongoDBHandler.php
Normal file
42
src/Monolog/Handler/MongoDBHandler.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Monolog package.
|
||||
*
|
||||
* (c) Thomas Tourlourat <thomas@tourlourat.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Monolog\Handler;
|
||||
|
||||
use Monolog\Logger;
|
||||
|
||||
/**
|
||||
* Logs to a MongoDB database.
|
||||
*
|
||||
* usage example:
|
||||
*
|
||||
* $log = new Logger('application');
|
||||
* $mongodb = new MongoDBHandler(new \Mongo("mongodb://localhost:27017"), "logs", "prod");
|
||||
* $log->pushHandler($mongodb);
|
||||
*
|
||||
* @author Thomas Tourlourat <thomas@tourlourat.com>
|
||||
*/
|
||||
class MongoDBHandler extends AbstractProcessingHandler {
|
||||
|
||||
private $mongoCollection;
|
||||
|
||||
public function __construct(\Mongo $mongo, $database, $collection, $level = Logger::DEBUG, $bubble = true) {
|
||||
$this->mongoCollection = $this->mongo->selectCollection($database, $collection);
|
||||
|
||||
parent::__construct($level, $bubble);
|
||||
}
|
||||
|
||||
protected function write(array $record) {
|
||||
unset($record["formatted"]);
|
||||
$this->mongoCollection->save($record);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user