mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-08 06:06:40 +02:00
@@ -51,24 +51,6 @@ abstract class AbstractHandler implements HandlerInterface
|
||||
return $record['level'] >= $this->level;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function handle(array $record)
|
||||
{
|
||||
if ($record['level'] < $this->level) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$record = $this->processRecord($record);
|
||||
|
||||
$record['message'] = $this->getFormatter()->format($record);
|
||||
|
||||
$this->write($record);
|
||||
|
||||
return false === $this->bubble;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@@ -171,14 +153,6 @@ abstract class AbstractHandler implements HandlerInterface
|
||||
$this->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the record down to the log of the implementing handler
|
||||
*
|
||||
* @param array $record
|
||||
* @return void
|
||||
*/
|
||||
abstract protected function write(array $record);
|
||||
|
||||
/**
|
||||
* Gets the default formatter.
|
||||
*
|
||||
@@ -188,21 +162,4 @@ abstract class AbstractHandler implements HandlerInterface
|
||||
{
|
||||
return new LineFormatter();
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes a record.
|
||||
*
|
||||
* @param array $record
|
||||
* @return array
|
||||
*/
|
||||
protected function processRecord(array $record)
|
||||
{
|
||||
if ($this->processors) {
|
||||
foreach ($this->processors as $processor) {
|
||||
$record = call_user_func($processor, $record);
|
||||
}
|
||||
}
|
||||
|
||||
return $record;
|
||||
}
|
||||
}
|
||||
|
80
src/Monolog/Handler/AbstractProcessingHandler.php
Normal file
80
src/Monolog/Handler/AbstractProcessingHandler.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Monolog package.
|
||||
*
|
||||
* (c) Jordi Boggiano <j.boggiano@seld.be>
|
||||
*
|
||||
* 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;
|
||||
use Monolog\Formatter\FormatterInterface;
|
||||
use Monolog\Formatter\LineFormatter;
|
||||
|
||||
/**
|
||||
* Base Handler class providing the Handler structure
|
||||
*
|
||||
* Classes extending it should (in most cases) only implement write($record)
|
||||
*
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author Christophe Coevoet <stof@notk.org>
|
||||
*/
|
||||
abstract class AbstractProcessingHandler extends AbstractHandler
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function handle(array $record)
|
||||
{
|
||||
if ($record['level'] < $this->level) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$record = $this->processRecord($record);
|
||||
|
||||
$record['message'] = $this->getFormatter()->format($record);
|
||||
|
||||
$this->write($record);
|
||||
|
||||
return false === $this->bubble;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function handleBatch(array $records)
|
||||
{
|
||||
foreach ($records as $record) {
|
||||
$this->handle($record);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the record down to the log of the implementing handler
|
||||
*
|
||||
* @param array $record
|
||||
* @return void
|
||||
*/
|
||||
abstract protected function write(array $record);
|
||||
|
||||
/**
|
||||
* Processes a record.
|
||||
*
|
||||
* @param array $record
|
||||
* @return array
|
||||
*/
|
||||
protected function processRecord(array $record)
|
||||
{
|
||||
if ($this->processors) {
|
||||
foreach ($this->processors as $processor) {
|
||||
$record = call_user_func($processor, $record);
|
||||
}
|
||||
}
|
||||
|
||||
return $record;
|
||||
}
|
||||
}
|
@@ -38,7 +38,6 @@ class BufferHandler extends AbstractHandler
|
||||
parent::__construct($level, $bubble);
|
||||
$this->handler = $handler;
|
||||
$this->bufferSize = $bufferSize;
|
||||
$this->bubble = $bubble;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,12 +64,4 @@ class BufferHandler extends AbstractHandler
|
||||
{
|
||||
$this->handler->handleBatch($this->buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implemented to comply with the AbstractHandler requirements. Can not be called.
|
||||
*/
|
||||
protected function write(array $record)
|
||||
{
|
||||
throw new \BadMethodCallException('This method should not be called directly on the BufferHandler.');
|
||||
}
|
||||
}
|
@@ -47,6 +47,14 @@ class FingersCrossedHandler extends AbstractHandler
|
||||
$this->stopBuffering = $stopBuffering;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isHandling(array $record)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@@ -84,12 +92,4 @@ class FingersCrossedHandler extends AbstractHandler
|
||||
{
|
||||
$this->buffering = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implemented to comply with the AbstractHandler requirements. Can not be called.
|
||||
*/
|
||||
protected function write(array $record)
|
||||
{
|
||||
throw new \BadMethodCallException('This method should not be called directly on the FingersCrossedHandler.');
|
||||
}
|
||||
}
|
||||
|
@@ -19,7 +19,7 @@ use Monolog\Formatter\WildfireFormatter;
|
||||
*
|
||||
* @author Eric Clemmons (@ericclemmons) <eric@uxdriven.com>
|
||||
*/
|
||||
class FirePHPHandler extends AbstractHandler
|
||||
class FirePHPHandler extends AbstractProcessingHandler
|
||||
{
|
||||
/**
|
||||
* WildFire JSON header message format
|
||||
|
@@ -11,8 +11,6 @@
|
||||
|
||||
namespace Monolog\Handler;
|
||||
|
||||
use Monolog\Logger;
|
||||
|
||||
/**
|
||||
* Forwards records to multiple handlers
|
||||
*
|
||||
@@ -23,15 +21,35 @@ class GroupHandler extends AbstractHandler
|
||||
protected $handlers;
|
||||
|
||||
/**
|
||||
* @param Array $handlers Array of Handlers or factory callbacks($record, $fingersCrossedHandler).
|
||||
* @param array $handlers Array of Handlers.
|
||||
* @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not
|
||||
*/
|
||||
public function __construct(array $handlers, $bubble = false)
|
||||
{
|
||||
foreach ($handlers as $handler) {
|
||||
if (!$handler instanceof HandlerInterface) {
|
||||
throw new \InvalidArgumentException('The first argument of the GroupHandler must be an array of HandlerInterface instances.');
|
||||
}
|
||||
}
|
||||
|
||||
$this->handlers = $handlers;
|
||||
$this->bubble = $bubble;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isHandling(array $record)
|
||||
{
|
||||
foreach ($this->handlers as $handler) {
|
||||
if ($handler->isHandling($record)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@@ -40,6 +58,7 @@ class GroupHandler extends AbstractHandler
|
||||
foreach ($this->handlers as $handler) {
|
||||
$handler->handle($record);
|
||||
}
|
||||
|
||||
return false === $this->bubble;
|
||||
}
|
||||
|
||||
@@ -52,12 +71,4 @@ class GroupHandler extends AbstractHandler
|
||||
$handler->handleBatch($records);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implemented to comply with the AbstractHandler requirements. Can not be called.
|
||||
*/
|
||||
protected function write(array $record)
|
||||
{
|
||||
throw new \BadMethodCallException('This method should not be called directly on the GroupHandler.');
|
||||
}
|
||||
}
|
||||
|
@@ -16,7 +16,7 @@ namespace Monolog\Handler;
|
||||
*
|
||||
* @author Gyula Sallai
|
||||
*/
|
||||
abstract class MailHandler extends AbstractHandler
|
||||
abstract class MailHandler extends AbstractProcessingHandler
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@@ -34,11 +34,4 @@ class NullHandler extends AbstractHandler
|
||||
|
||||
return false === $this->bubble;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function write(array $record)
|
||||
{
|
||||
}
|
||||
}
|
@@ -21,7 +21,7 @@ use Monolog\Logger;
|
||||
*
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
*/
|
||||
class StreamHandler extends AbstractHandler
|
||||
class StreamHandler extends AbstractProcessingHandler
|
||||
{
|
||||
protected $stream;
|
||||
protected $url;
|
||||
|
@@ -27,7 +27,7 @@ use Monolog\Logger;
|
||||
*
|
||||
* @author Sven Paulus <sven@karlsruhe.org>
|
||||
*/
|
||||
class SyslogHandler extends AbstractHandler
|
||||
class SyslogHandler extends AbstractProcessingHandler
|
||||
{
|
||||
/**
|
||||
* Translates Monolog log levels to syslog log priorities.
|
||||
|
@@ -20,7 +20,7 @@ use Monolog\Logger;
|
||||
*
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
*/
|
||||
class TestHandler extends AbstractHandler
|
||||
class TestHandler extends AbstractProcessingHandler
|
||||
{
|
||||
protected $records;
|
||||
protected $recordsByLevel;
|
||||
|
Reference in New Issue
Block a user