1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-10-20 16:16:37 +02:00

Made the write method protected

Tests are not a good reason to make it public.
This commit is contained in:
Christophe Coevoet
2011-04-06 13:22:06 +02:00
parent 87332a3e4e
commit 3cb3dbdc8f
16 changed files with 125 additions and 124 deletions

View File

@@ -69,6 +69,7 @@ abstract class AbstractHandler implements HandlerInterface
$record = $this->formatter->format($record);
$this->write($record);
return false === $this->bubble;
}
@@ -82,14 +83,6 @@ abstract class AbstractHandler implements HandlerInterface
}
}
/**
* Writes the record down to the log of the implementing handler
*
* @param array $record
* @return void
*/
abstract public function write(array $record);
/**
* Closes the handler.
*
@@ -178,6 +171,14 @@ 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.
*

View File

@@ -63,7 +63,7 @@ class BufferHandler extends AbstractHandler
/**
* Implemented to comply with the AbstractHandler requirements. Can not be called.
*/
public function write(array $record)
protected function write(array $record)
{
throw new \BadMethodCallException('This method should not be called directly on the FingersCrossedHandler.');
}

View File

@@ -85,7 +85,7 @@ class FingersCrossedHandler extends AbstractHandler
/**
* Implemented to comply with the AbstractHandler requirements. Can not be called.
*/
public function write(array $record)
protected function write(array $record)
{
throw new \BadMethodCallException('This method should not be called directly on the FingersCrossedHandler.');
}

View File

@@ -38,7 +38,7 @@ class NullHandler extends AbstractHandler
/**
* {@inheritdoc}
*/
public function write(array $record)
protected function write(array $record)
{
}
}

View File

@@ -52,19 +52,6 @@ class RotatingFileHandler extends StreamHandler
parent::__construct($timedFilename, $level, $bubble);
}
/**
* {@inheritdoc}
*/
public function write(array $record)
{
// on the first record written, if the log is new, we should rotate (once per day)
if (null === $this->mustRotate) {
$this->mustRotate = !file_exists($this->url);
}
parent::write($record);
}
/**
* {@inheritdoc}
*/
@@ -77,6 +64,19 @@ class RotatingFileHandler extends StreamHandler
}
}
/**
* {@inheritdoc}
*/
protected function write(array $record)
{
// on the first record written, if the log is new, we should rotate (once per day)
if (null === $this->mustRotate) {
$this->mustRotate = !file_exists($this->url);
}
parent::write($record);
}
/**
* Rotates the files.
*/

View File

@@ -41,24 +41,6 @@ class StreamHandler extends AbstractHandler
}
}
/**
* {@inheritdoc}
*/
public function write(array $record)
{
if (null === $this->stream) {
if (!$this->url) {
throw new \LogicException('Missing stream url, the stream can not be opened. This may be caused by a premature call to close().');
}
$this->stream = fopen($this->url, 'a');
if (!is_resource($this->stream)) {
$this->stream = null;
throw new \UnexpectedValueException('The stream could not be opened, "'.$this->url.'" may be an invalid url.');
}
}
fwrite($this->stream, (string) $record['message']);
}
/**
* {@inheritdoc}
*/
@@ -69,4 +51,22 @@ class StreamHandler extends AbstractHandler
$this->stream = null;
}
}
/**
* {@inheritdoc}
*/
protected function write(array $record)
{
if (null === $this->stream) {
if (!$this->url) {
throw new \LogicException('Missing stream url, the stream can not be opened. This may be caused by a premature call to close().');
}
$this->stream = @fopen($this->url, 'a');
if (!is_resource($this->stream)) {
$this->stream = null;
throw new \UnexpectedValueException('The stream could not be opened, "'.$this->url.'" may be an invalid url.');
}
}
fwrite($this->stream, (string) $record['message']);
}
}

View File

@@ -93,16 +93,16 @@ class SyslogHandler extends AbstractHandler
/**
* {@inheritdoc}
*/
public function write(array $record)
public function close()
{
syslog($this->logLevels[$record['level']], (string) $record['message']);
closelog();
}
/**
* {@inheritdoc}
*/
public function close()
protected function write(array $record)
{
closelog();
syslog($this->logLevels[$record['level']], (string) $record['message']);
}
}

View File

@@ -89,7 +89,7 @@ class TestHandler extends AbstractHandler
/**
* {@inheritdoc}
*/
public function write(array $record)
protected function write(array $record)
{
$this->recordsByLevel[$record['level']][] = $record;
$this->records[] = $record;