1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-10-25 02:26:16 +02:00
This commit is contained in:
Jordi Boggiano
2012-06-14 15:46:17 +02:00
parent 1530322897
commit da33c84d07
46 changed files with 193 additions and 206 deletions

View File

@@ -32,7 +32,7 @@ abstract class AbstractHandler implements HandlerInterface
protected $processors = array();
/**
* @param integer $level The minimum logging level at which this handler will be triggered
* @param integer $level The minimum logging level at which this handler will be triggered
* @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not
*/
public function __construct($level = Logger::DEBUG, $bubble = true)
@@ -87,6 +87,7 @@ abstract class AbstractHandler implements HandlerInterface
if (!$this->processors) {
throw new \LogicException('You tried to pop from an empty processor stack.');
}
return array_shift($this->processors);
}
@@ -155,8 +156,8 @@ abstract class AbstractHandler implements HandlerInterface
public function __destruct()
{
try {
$this->close();
} catch(\Exception $e) {
$this->close();
} catch (\Exception $e) {
// do nothing
}
}

View File

@@ -11,10 +11,6 @@
namespace Monolog\Handler;
use Monolog\Logger;
use Monolog\Formatter\FormatterInterface;
use Monolog\Formatter\LineFormatter;
/**
* Base Handler class providing the Handler structure
*
@@ -46,7 +42,7 @@ abstract class AbstractProcessingHandler extends AbstractHandler
/**
* Writes the record down to the log of the implementing handler
*
* @param array $record
* @param array $record
* @return void
*/
abstract protected function write(array $record);
@@ -54,7 +50,7 @@ abstract class AbstractProcessingHandler extends AbstractHandler
/**
* Processes a record.
*
* @param array $record
* @param array $record
* @return array
*/
protected function processRecord(array $record)

View File

@@ -28,10 +28,10 @@ class BufferHandler extends AbstractHandler
protected $buffer = array();
/**
* @param HandlerInterface $handler Handler.
* @param integer $bufferSize How many entries should be buffered at most, beyond that the oldest items are removed from the buffer.
* @param integer $level The minimum logging level at which this handler will be triggered
* @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not
* @param HandlerInterface $handler Handler.
* @param integer $bufferSize How many entries should be buffered at most, beyond that the oldest items are removed from the buffer.
* @param integer $level The minimum logging level at which this handler will be triggered
* @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not
*/
public function __construct(HandlerInterface $handler, $bufferSize = 0, $level = Logger::DEBUG, $bubble = true)
{
@@ -65,7 +65,7 @@ class BufferHandler extends AbstractHandler
*/
public function close()
{
if($this->buffer) {
if ($this->buffer) {
$this->handler->handleBatch($this->buffer);
$this->buffer = array();
}

View File

@@ -11,7 +11,6 @@
namespace Monolog\Handler;
use Monolog\Logger;
use Monolog\Formatter\ChromePHPFormatter;
/**
@@ -31,9 +30,9 @@ class ChromePHPHandler extends AbstractProcessingHandler
*/
const HEADER_NAME = 'X-ChromePhp-Data';
static protected $initialized = false;
protected static $initialized = false;
static protected $json = array(
protected static $json = array(
'version' => self::VERSION,
'columns' => array('label', 'log', 'backtrace', 'type'),
'rows' => array(),
@@ -124,4 +123,4 @@ class ChromePHPHandler extends AbstractProcessingHandler
return !isset($_SERVER['HTTP_USER_AGENT'])
|| preg_match('{\bChrome/\d+[\.\d+]*\b}', $_SERVER['HTTP_USER_AGENT']);
}
}
}

View File

@@ -1,28 +1,28 @@
<?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\FingersCrossed;
/**
* Interface for activation strategies for the FingersCrossedHandler.
*
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
*/
interface ActivationStrategyInterface
{
/**
* Returns whether the given record activates the handler.
*
* @param array $record
* @return Boolean
*/
function isHandlerActivated(array $record);
}
<?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\FingersCrossed;
/**
* Interface for activation strategies for the FingersCrossedHandler.
*
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
*/
interface ActivationStrategyInterface
{
/**
* Returns whether the given record activates the handler.
*
* @param array $record
* @return Boolean
*/
public function isHandlerActivated(array $record);
}

View File

@@ -1,32 +1,32 @@
<?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\FingersCrossed;
/**
* Error level based activation strategy.
*
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
*/
class ErrorLevelActivationStrategy implements ActivationStrategyInterface
{
private $actionLevel;
public function __construct($actionLevel)
{
$this->actionLevel = $actionLevel;
}
public function isHandlerActivated(array $record)
{
return $record['level'] >= $this->actionLevel;
}
}
<?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\FingersCrossed;
/**
* Error level based activation strategy.
*
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
*/
class ErrorLevelActivationStrategy implements ActivationStrategyInterface
{
private $actionLevel;
public function __construct($actionLevel)
{
$this->actionLevel = $actionLevel;
}
public function isHandlerActivated(array $record)
{
return $record['level'] >= $this->actionLevel;
}
}

View File

@@ -34,11 +34,11 @@ class FingersCrossedHandler extends AbstractHandler
protected $stopBuffering;
/**
* @param callback|HandlerInterface $handler Handler or factory callback($record, $fingersCrossedHandler).
* @param callback|HandlerInterface $handler Handler or factory callback($record, $fingersCrossedHandler).
* @param int|ActivationStrategyInterface $activationStrategy Strategy which determines when this handler takes action
* @param int $bufferSize How many entries should be buffered at most, beyond that the oldest items are removed from the buffer.
* @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not
* @param Boolean $stopBuffering Whether the handler should stop buffering after being triggered (default true)
* @param int $bufferSize How many entries should be buffered at most, beyond that the oldest items are removed from the buffer.
* @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not
* @param Boolean $stopBuffering Whether the handler should stop buffering after being triggered (default true)
*/
public function __construct($handler, $activationStrategy = null, $bufferSize = 0, $bubble = true, $stopBuffering = true)
{

View File

@@ -11,7 +11,6 @@
namespace Monolog\Handler;
use Monolog\Logger;
use Monolog\Formatter\WildfireFormatter;
/**
@@ -57,9 +56,9 @@ class FirePHPHandler extends AbstractProcessingHandler
/**
* Base header creation function used by init headers & record headers
*
* @param array $meta Wildfire Plugin, Protocol & Structure Indexes
* @param string $message Log message
* @return array Complete header string ready for the client as key and message as value
* @param array $meta Wildfire Plugin, Protocol & Structure Indexes
* @param string $message Log message
* @return array Complete header string ready for the client as key and message as value
*/
protected function createHeader(array $meta, $message)
{
@@ -72,7 +71,7 @@ class FirePHPHandler extends AbstractProcessingHandler
* Creates message header from record
*
* @see createHeader()
* @param array $record
* @param array $record
* @return string
*/
protected function createRecordHeader(array $record)
@@ -158,4 +157,4 @@ class FirePHPHandler extends AbstractProcessingHandler
|| preg_match('{\bFirePHP/\d+\.\d+\b}', $_SERVER['HTTP_USER_AGENT'])
|| isset($_SERVER['HTTP_X_FIREPHP_VERSION']);
}
}
}

View File

@@ -17,7 +17,7 @@ use Monolog\Handler\AbstractProcessingHandler;
use Monolog\Formatter\GelfMessageFormatter;
/**
* Handler to send messages to a Graylog2 (http://www.graylog2.org) server
* Handler to send messages to a Graylog2 (http://www.graylog2.org) server
*
* @author Matt Lehner <mlehner@gmail.com>
*/
@@ -30,8 +30,8 @@ class GelfHandler extends AbstractProcessingHandler
/**
* @param Gelf\IMessagePublisher $publisher a publisher object
* @param integer $level The minimum logging level at which this handler will be triggered
* @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not
* @param integer $level The minimum logging level at which this handler will be triggered
* @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not
*/
public function __construct(IMessagePublisher $publisher, $level = Logger::DEBUG, $bubble = true)
{

View File

@@ -21,8 +21,8 @@ class GroupHandler extends AbstractHandler
protected $handlers;
/**
* @param array $handlers Array of Handlers.
* @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not
* @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 = true)
{

View File

@@ -27,51 +27,51 @@ interface HandlerInterface
*
* @return Boolean
*/
function isHandling(array $record);
public function isHandling(array $record);
/**
* Handles a record.
*
* The return value of this function controls the bubbling process of the handler stack.
*
* @param array $record The record to handle
* @param array $record The record to handle
* @return Boolean True means that this handler handled the record, and that bubbling is not permitted.
* False means the record was either not processed or that this handler allows bubbling.
*/
function handle(array $record);
public function handle(array $record);
/**
* Handles a set of records at once.
*
* @param array $records The records to handle (an array of record arrays)
*/
function handleBatch(array $records);
public function handleBatch(array $records);
/**
* Adds a processor in the stack.
*
* @param callable $callback
*/
function pushProcessor($callback);
public function pushProcessor($callback);
/**
* Removes the processor on top of the stack and returns it.
*
* @return callable
*/
function popProcessor();
public function popProcessor();
/**
* Sets the formatter.
*
* @param FormatterInterface $formatter
*/
function setFormatter(FormatterInterface $formatter);
public function setFormatter(FormatterInterface $formatter);
/**
* Gets the formatter.
*
* @return FormatterInterface
*/
function getFormatter();
public function getFormatter();
}

View File

@@ -41,7 +41,7 @@ abstract class MailHandler extends AbstractProcessingHandler
* Send a mail with the given content
*
* @param string $content
* @param array $records the array of log records that formed this content
* @param array $records the array of log records that formed this content
*/
abstract protected function send($content, array $records);
@@ -52,4 +52,4 @@ abstract class MailHandler extends AbstractProcessingHandler
{
$this->send((string) $record['formatted'], array($record));
}
}
}

View File

@@ -27,11 +27,11 @@ class NativeMailerHandler extends MailHandler
);
/**
* @param string|array $to The receiver of the mail
* @param string $subject The subject of the mail
* @param string $from The sender of the mail
* @param integer $level The minimum logging level at which this handler will be triggered
* @param boolean $bubble Whether the messages that are handled can bubble up the stack or not
* @param string|array $to The receiver of the mail
* @param string $subject The subject of the mail
* @param string $from The sender of the mail
* @param integer $level The minimum logging level at which this handler will be triggered
* @param boolean $bubble Whether the messages that are handled can bubble up the stack or not
*/
public function __construct($to, $subject, $from, $level = Logger::ERROR, $bubble = true)
{
@@ -62,4 +62,4 @@ class NativeMailerHandler extends MailHandler
mail($to, $this->subject, wordwrap($content, 70), implode("\r\n", $this->headers) . "\r\n");
}
}
}
}

View File

@@ -42,4 +42,4 @@ class NullHandler extends AbstractHandler
return true;
}
}
}

View File

@@ -28,10 +28,10 @@ class RotatingFileHandler extends StreamHandler
protected $mustRotate;
/**
* @param string $filename
* @param string $filename
* @param integer $maxFiles The maximal amount of files to keep (0 means unlimited)
* @param integer $level The minimum logging level at which this handler will be triggered
* @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not
* @param integer $level The minimum logging level at which this handler will be triggered
* @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not
*/
public function __construct($filename, $maxFiles = 0, $level = Logger::DEBUG, $bubble = true)
{
@@ -106,4 +106,4 @@ class RotatingFileHandler extends StreamHandler
}
}
}
}
}

View File

@@ -26,8 +26,8 @@ class StreamHandler extends AbstractProcessingHandler
protected $url;
/**
* @param string $stream
* @param integer $level The minimum logging level at which this handler will be triggered
* @param string $stream
* @param integer $level The minimum logging level at which this handler will be triggered
* @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not
*/
public function __construct($stream, $level = Logger::DEBUG, $bubble = true)

View File

@@ -24,10 +24,10 @@ class SwiftMailerHandler extends MailHandler
protected $message;
/**
* @param \Swift_Mailer $mailer The mailer to use
* @param \Swift_Mailer $mailer The mailer to use
* @param callback|\Swift_Message $message An example message for real messages, only the body will be replaced
* @param integer $level The minimum logging level at which this handler will be triggered
* @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not
* @param integer $level The minimum logging level at which this handler will be triggered
* @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not
*/
public function __construct(\Swift_Mailer $mailer, $message, $level = Logger::ERROR, $bubble = true)
{
@@ -52,4 +52,4 @@ class SwiftMailerHandler extends MailHandler
$this->mailer->send($message);
}
}
}

View File

@@ -58,10 +58,10 @@ class SyslogHandler extends AbstractProcessingHandler
);
/**
* @param string $ident
* @param mixed $facility
* @param integer $level The minimum logging level at which this handler will be triggered
* @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not
* @param string $ident
* @param mixed $facility
* @param integer $level The minimum logging level at which this handler will be triggered
* @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not
*/
public function __construct($ident, $facility = LOG_USER, $level = Logger::DEBUG, $bubble = true)
{
@@ -81,7 +81,7 @@ class SyslogHandler extends AbstractProcessingHandler
// convert textual description of facility to syslog constant
if (array_key_exists(strtolower($facility), $this->facilities)) {
$facility = $this->facilities[strtolower($facility)];
} else if (!in_array($facility, array_values($this->facilities), true)) {
} elseif (!in_array($facility, array_values($this->facilities), true)) {
throw new \UnexpectedValueException('Unknown facility value "'.$facility.'" given');
}

View File

@@ -117,4 +117,4 @@ class TestHandler extends AbstractProcessingHandler
$this->recordsByLevel[$record['level']][] = $record;
$this->records[] = $record;
}
}
}