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

Renamed message to record

This commit is contained in:
Jordi Boggiano
2011-02-25 22:54:01 +01:00
parent efc2bd656b
commit 6c24217c56
16 changed files with 175 additions and 176 deletions

View File

@@ -17,7 +17,7 @@ use Monolog\Formatter\LineFormatter;
/**
* Base Handler class providing the Handler structure
*
* Classes extending it should (in most cases) only implement write($message)
* Classes extending it should (in most cases) only implement write($record)
*
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
@@ -35,34 +35,33 @@ abstract class AbstractHandler implements HandlerInterface
$this->bubble = $bubble;
}
public function isHandling($message)
public function isHandling($record)
{
return $message['level'] >= $this->level;
return $record['level'] >= $this->level;
}
public function handle($message)
public function handle($record)
{
if ($message['level'] < $this->level) {
if ($record['level'] < $this->level) {
return false;
}
$originalMessage = $message;
if ($this->processors) {
foreach ($this->processors as $processor) {
$message = call_user_func($processor, $message, $this);
$record = call_user_func($processor, $record, $this);
}
}
if (!$this->formatter) {
$this->formatter = $this->getDefaultFormatter();
}
$message = $this->formatter->format($message);
$record = $this->formatter->format($record);
$this->write($message);
$this->write($record);
return false === $this->bubble;
}
abstract public function write($message);
abstract public function write($record);
public function close()
{

View File

@@ -14,11 +14,11 @@ namespace Monolog\Handler;
use Monolog\Logger;
/**
* Buffers all messages until a certain level is reached
* Buffers all records until a certain level is reached
*
* The advantage of this approach is that you don't get any clutter in your log files.
* Only requests which actually trigger an error (or whatever your actionLevel is) will be
* in the logs, but they will contain all messages, not only those above the level threshold.
* in the logs, but they will contain all records, not only those above the level threshold.
*
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
@@ -31,7 +31,7 @@ class FingersCrossedHandler extends AbstractHandler
protected $buffer = array();
/**
* @param callback|HandlerInterface $handler Handler or factory callback($message, $fingersCrossedHandler).
* @param callback|HandlerInterface $handler Handler or factory callback($record, $fingersCrossedHandler).
* @param int $actionLevel The level at which this handler is triggered.
* @param int $bufferSize How many entries should be buffered at most, beyond that the oldest items are removed from the buffer.
* @param Boolean $bubble
@@ -45,39 +45,39 @@ class FingersCrossedHandler extends AbstractHandler
}
/**
* Handles a message
* Handles a record
*
* Messages are buffered until one of them matches the actionLevel. From then
* on, unless reset() is called, all messages are passed to the wrapped handler.
* Records are buffered until one of them matches the actionLevel. From then
* on, unless reset() is called, all records are passed to the wrapped handler.
*
* @param array $message Message
* @return Boolean Whether the message was handled
* @param array $record Records
* @return Boolean Whether the record was handled
*/
public function handle($message)
public function handle($record)
{
if ($this->buffering) {
$this->buffer[] = $message;
$this->buffer[] = $record;
if ($this->bufferSize > 0 && count($this->buffer) > $this->bufferSize) {
array_shift($this->buffer);
}
if ($message['level'] >= $this->actionLevel) {
if ($record['level'] >= $this->actionLevel) {
$this->buffering = false;
if (!$this->handler instanceof AbstractHandler) {
$this->handler = $this->handler($message, $this);
$this->handler = $this->handler($record, $this);
}
foreach ($this->buffer as $message) {
$this->handler->handle($message);
foreach ($this->buffer as $record) {
$this->handler->handle($record);
}
$this->buffer = array();
}
} else {
$this->handler->handle($message);
$this->handler->handle($record);
}
return false === $this->bubble;
}
/**
* Resets the state of the handler. Stops forwarding messages to the wrapped handler.
* Resets the state of the handler. Stops forwarding records to the wrapped handler.
*/
public function reset()
{
@@ -87,7 +87,7 @@ class FingersCrossedHandler extends AbstractHandler
/**
* Implemented to comply with the AbstractHandler rqeuirements. Can not be called.
*/
public function write($message)
public function write($record)
{
throw new \LogicException('This method should not be called directly on the FingersCrossedHandler.');
}

View File

@@ -18,7 +18,7 @@ namespace Monolog\Handler;
*/
interface HandlerInterface
{
public function isHandling($message);
public function isHandling($record);
public function handle($message);
public function handle($record);
}

View File

@@ -16,22 +16,22 @@ use Monolog\Logger;
/**
* Blackhole
*
* Any message it can handle will be thrown away. This can be used
* Any record it can handle will be thrown away. This can be used
* to put on top of an existing stack to override it temporarily.
*
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
class NullHandler extends AbstractHandler
{
public function handle($message)
public function handle($record)
{
if ($message['level'] < $this->level) {
if ($record['level'] < $this->level) {
return false;
}
return false === $this->bubble;
}
public function write($message)
public function write($record)
{
}
}

View File

@@ -36,7 +36,7 @@ class StreamHandler extends AbstractHandler
}
}
public function write($message)
public function write($record)
{
if (null === $this->stream) {
if (!$this->url) {
@@ -47,7 +47,7 @@ class StreamHandler extends AbstractHandler
throw new \UnexpectedValueException('The stream could not be opened, "'.$this->url.'" may be an invalid url.');
}
}
fwrite($this->stream, (string) $message['message']);
fwrite($this->stream, (string) $record['message']);
}
public function close()

View File

@@ -16,78 +16,78 @@ use Monolog\Logger;
/**
* Used for testing purposes.
*
* It records all messages and gives you access to them for verification.
* It records all records and gives you access to them for verification.
*
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
class TestHandler extends AbstractHandler
{
protected $messages;
protected $messagesByLevel;
protected $records;
protected $recordsByLevel;
public function getMessages()
public function getRecords()
{
return $this->messages;
return $this->records;
}
public function hasError($message)
public function hasError($record)
{
return $this->hasMessage($message, Logger::ERROR);
return $this->hasRecord($record, Logger::ERROR);
}
public function hasWarning($message)
public function hasWarning($record)
{
return $this->hasMessage($message, Logger::WARNING);
return $this->hasRecord($record, Logger::WARNING);
}
public function hasInfo($message)
public function hasInfo($record)
{
return $this->hasMessage($message, Logger::INFO);
return $this->hasRecord($record, Logger::INFO);
}
public function hasDebug($message)
public function hasDebug($record)
{
return $this->hasMessage($message, Logger::DEBUG);
return $this->hasRecord($record, Logger::DEBUG);
}
public function hasErrorMessages()
public function hasErrorrecords()
{
return isset($this->messagesByLevel[Logger::ERROR]);
return isset($this->recordsByLevel[Logger::ERROR]);
}
public function hasWarningMessages()
public function hasWarningrecords()
{
return isset($this->messagesByLevel[Logger::WARNING]);
return isset($this->recordsByLevel[Logger::WARNING]);
}
public function hasInfoMessages()
public function hasInforecords()
{
return isset($this->messagesByLevel[Logger::INFO]);
return isset($this->recordsByLevel[Logger::INFO]);
}
public function hasDebugMessages()
public function hasDebugrecords()
{
return isset($this->messagesByLevel[Logger::DEBUG]);
return isset($this->recordsByLevel[Logger::DEBUG]);
}
protected function hasMessage($message, $level = null)
protected function hasRecord($record, $level = null)
{
if (null === $level) {
$messages = $this->messages;
$records = $this->records;
} else {
$messages = $this->messagesByLevel[$level];
$records = $this->recordsByLevel[$level];
}
foreach ($messages as $msg) {
if ($msg['message'] === $message) {
foreach ($records as $msg) {
if ($msg['message'] === $record) {
return true;
}
}
return false;
}
public function write($message)
public function write($record)
{
$this->messagesByLevel[$message['level']][] = $message;
$this->messages[] = $message;
$this->recordsByLevel[$record['level']][] = $record;
$this->records[] = $record;
}
}