1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-02-24 15:02:28 +01:00

Add MongoDB handler

This commit is contained in:
armetiz 2012-02-20 11:11:46 +01:00
parent 3d4e60d0cb
commit a04bec0bec

View File

@ -0,0 +1,43 @@
<?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');
* $syslog = new MongoDBHandler(new \Mongo("mongodb://localhost:27017"), "logs", "prod");
* $log->pushHandler($syslog);
*
* @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);
}
}