1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-04 12:17:35 +02:00

Minor CS fixes, updated changelog

This commit is contained in:
Jordi Boggiano
2012-04-22 16:36:31 +02:00
parent 5f40e7e942
commit b42da84c12
4 changed files with 41 additions and 43 deletions

View File

@@ -6,6 +6,7 @@
handle the given log level handle the given log level
* Added ChromePHPHandler * Added ChromePHPHandler
* Added MongoDBHandler * Added MongoDBHandler
* Added SocketHandler (for use with syslog-ng for example)
* Added NormalizerFormatter * Added NormalizerFormatter
* Added the possibility to change the activation strategy of the FingersCrossedHandler * Added the possibility to change the activation strategy of the FingersCrossedHandler
* Added possibility to show microseconds in logs * Added possibility to show microseconds in logs

View File

@@ -33,5 +33,5 @@ $logger->addInfo('My logger is now ready');
In this example, using syslog-ng, you should see the log on the log server: In this example, using syslog-ng, you should see the log on the log server:
cweb1 [2012-02-26 00:12:03] my_logger.INFO: My logger is now ready [] [] cweb1 [2012-02-26 00:12:03] my_logger.INFO: My logger is now ready [] []

View File

@@ -15,13 +15,12 @@ use Monolog\Logger;
/** /**
* Stores to any socket - uses fsockopen() or pfsockopen(). * Stores to any socket - uses fsockopen() or pfsockopen().
* *
* @author Pablo de Leon Belloc <pablolb@gmail.com> * @author Pablo de Leon Belloc <pablolb@gmail.com>
* @see http://php.net/manual/en/function.fsockopen.php * @see http://php.net/manual/en/function.fsockopen.php
*/ */
class SocketHandler extends AbstractProcessingHandler class SocketHandler extends AbstractProcessingHandler
{ {
private $connectionString; private $connectionString;
private $connectionTimeout; private $connectionTimeout;
private $resource; private $resource;
@@ -44,9 +43,9 @@ class SocketHandler extends AbstractProcessingHandler
/** /**
* Connect (if necessary) and write to the socket * Connect (if necessary) and write to the socket
* *
* @param array $record * @param array $record
* *
* @throws \UnexpectedValueException * @throws \UnexpectedValueException
* @throws \RuntimeException * @throws \RuntimeException
*/ */
@@ -61,10 +60,9 @@ class SocketHandler extends AbstractProcessingHandler
*/ */
public function close() public function close()
{ {
if ($this->isPersistent()) { if (!$this->isPersistent()) {
return; $this->closeSocket();
} }
$this->closeSocket();
} }
/** /**
@@ -80,8 +78,8 @@ class SocketHandler extends AbstractProcessingHandler
/** /**
* Set socket connection to nbe persistent. It only has effect before the connection is initiated. * Set socket connection to nbe persistent. It only has effect before the connection is initiated.
* *
* @param type $boolean * @param type $boolean
*/ */
public function setPersistent($boolean) public function setPersistent($boolean)
{ {
@@ -90,9 +88,9 @@ class SocketHandler extends AbstractProcessingHandler
/** /**
* Set connection timeout. Only has effect before we connect. * Set connection timeout. Only has effect before we connect.
* *
* @param integer $seconds * @param integer $seconds
* *
* @see http://php.net/manual/en/function.fsockopen.php * @see http://php.net/manual/en/function.fsockopen.php
*/ */
public function setConnectionTimeout($seconds) public function setConnectionTimeout($seconds)
@@ -103,9 +101,9 @@ class SocketHandler extends AbstractProcessingHandler
/** /**
* Set write timeout. Only has effect before we connect. * Set write timeout. Only has effect before we connect.
* *
* @param type $seconds * @param type $seconds
* *
* @see http://php.net/manual/en/function.stream-set-timeout.php * @see http://php.net/manual/en/function.stream-set-timeout.php
*/ */
public function setTimeout($seconds) public function setTimeout($seconds)
@@ -116,7 +114,7 @@ class SocketHandler extends AbstractProcessingHandler
/** /**
* Get current connection string * Get current connection string
* *
* @return string * @return string
*/ */
public function getConnectionString() public function getConnectionString()
@@ -126,7 +124,7 @@ class SocketHandler extends AbstractProcessingHandler
/** /**
* Get persistent setting * Get persistent setting
* *
* @return boolean * @return boolean
*/ */
public function isPersistent() public function isPersistent()
@@ -136,7 +134,7 @@ class SocketHandler extends AbstractProcessingHandler
/** /**
* Get current connection timeout setting * Get current connection timeout setting
* *
* @return float * @return float
*/ */
public function getConnectionTimeout() public function getConnectionTimeout()
@@ -146,7 +144,7 @@ class SocketHandler extends AbstractProcessingHandler
/** /**
* Get current in-transfer timeout * Get current in-transfer timeout
* *
* @return float * @return float
*/ */
public function getTimeout() public function getTimeout()
@@ -156,19 +154,19 @@ class SocketHandler extends AbstractProcessingHandler
/** /**
* Check to see if the socket is currently available. * Check to see if the socket is currently available.
* *
* UDP might appear to be connected but might fail when writing. See http://php.net/fsockopen for details. * UDP might appear to be connected but might fail when writing. See http://php.net/fsockopen for details.
* *
* @return boolean * @return boolean
*/ */
public function isConnected() public function isConnected()
{ {
return is_resource($this->resource) return is_resource($this->resource)
&& !feof($this->resource); // on TCP - other party can close connection. && !feof($this->resource); // on TCP - other party can close connection.
} }
/** /**
* Allow mock * Wrapper to allow mocking
*/ */
protected function pfsockopen() protected function pfsockopen()
{ {
@@ -176,7 +174,7 @@ class SocketHandler extends AbstractProcessingHandler
} }
/** /**
* Allow mock * Wrapper to allow mocking
*/ */
protected function fsockopen() protected function fsockopen()
{ {
@@ -184,15 +182,15 @@ class SocketHandler extends AbstractProcessingHandler
} }
/** /**
* Allow mock * Wrapper to allow mocking
*/ */
protected function stream_set_timeout() protected function streamSetTimeout()
{ {
return stream_set_timeout($this->resource, $this->timeout); return stream_set_timeout($this->resource, $this->timeout);
} }
/** /**
* Allow mock * Wrapper to allow mocking
*/ */
protected function fwrite($data) protected function fwrite($data)
{ {
@@ -200,9 +198,9 @@ class SocketHandler extends AbstractProcessingHandler
} }
/** /**
* Allow mock * Wrapper to allow mocking
*/ */
protected function stream_get_meta_data() protected function streamGetMetadata()
{ {
return stream_get_meta_data($this->resource); return stream_get_meta_data($this->resource);
} }
@@ -246,7 +244,7 @@ class SocketHandler extends AbstractProcessingHandler
private function setSocketTimeout() private function setSocketTimeout()
{ {
if (!$this->stream_set_timeout()) { if (!$this->streamSetTimeout()) {
throw new \UnexpectedValueException("Failed setting timeout with stream_set_timeout()"); throw new \UnexpectedValueException("Failed setting timeout with stream_set_timeout()");
} }
} }
@@ -261,7 +259,7 @@ class SocketHandler extends AbstractProcessingHandler
throw new \RuntimeException("Could not write to socket"); throw new \RuntimeException("Could not write to socket");
} }
$sent += $chunk; $sent += $chunk;
$socketInfo = $this->stream_get_meta_data(); $socketInfo = $this->streamGetMetadata();
if ($socketInfo['timed_out']) { if ($socketInfo['timed_out']) {
throw new \RuntimeException("Write timed-out"); throw new \RuntimeException("Write timed-out");
} }

View File

@@ -19,7 +19,6 @@ use Monolog\Logger;
*/ */
class SocketHandlerTest extends TestCase class SocketHandlerTest extends TestCase
{ {
/** /**
* @var Monolog\Handler\SocketHandler * @var Monolog\Handler\SocketHandler
*/ */
@@ -107,9 +106,9 @@ class SocketHandlerTest extends TestCase
*/ */
public function testExceptionIsThrownIfCannotSetTimeout() public function testExceptionIsThrownIfCannotSetTimeout()
{ {
$this->setMockHandler(array('stream_set_timeout')); $this->setMockHandler(array('streamSetTimeout'));
$this->handler->expects($this->once()) $this->handler->expects($this->once())
->method('stream_set_timeout') ->method('streamSetTimeout')
->will($this->returnValue(false)); ->will($this->returnValue(false));
$this->writeRecord('Hello world'); $this->writeRecord('Hello world');
} }
@@ -142,7 +141,7 @@ class SocketHandlerTest extends TestCase
*/ */
public function testWriteFailsIfStreamTimesOut() public function testWriteFailsIfStreamTimesOut()
{ {
$this->setMockHandler(array('fwrite', 'stream_get_meta_data')); $this->setMockHandler(array('fwrite', 'streamGetMetadata'));
$callback = function($arg) $callback = function($arg)
{ {
@@ -157,7 +156,7 @@ class SocketHandlerTest extends TestCase
->method('fwrite') ->method('fwrite')
->will($this->returnCallback($callback)); ->will($this->returnCallback($callback));
$this->handler->expects($this->exactly(1)) $this->handler->expects($this->exactly(1))
->method('stream_get_meta_data') ->method('streamGetMetadata')
->will($this->returnValue(array('timed_out' => true))); ->will($this->returnValue(array('timed_out' => true)));
@@ -169,7 +168,7 @@ class SocketHandlerTest extends TestCase
*/ */
public function testWriteFailsOnIncompleteWrite() public function testWriteFailsOnIncompleteWrite()
{ {
$this->setMockHandler(array('fwrite', 'stream_get_meta_data')); $this->setMockHandler(array('fwrite', 'streamGetMetadata'));
$res = $this->res; $res = $this->res;
$callback = function($string) use ($res) $callback = function($string) use ($res)
@@ -182,7 +181,7 @@ class SocketHandlerTest extends TestCase
->method('fwrite') ->method('fwrite')
->will($this->returnCallback($callback)); ->will($this->returnCallback($callback));
$this->handler->expects($this->exactly(1)) $this->handler->expects($this->exactly(1))
->method('stream_get_meta_data') ->method('streamGetMetadata')
->will($this->returnValue(array('timed_out' => false))); ->will($this->returnValue(array('timed_out' => false)));
$this->writeRecord('Hello world'); $this->writeRecord('Hello world');
@@ -252,7 +251,7 @@ class SocketHandlerTest extends TestCase
{ {
$this->res = fopen('php://memory', 'a'); $this->res = fopen('php://memory', 'a');
$defaultMethods = array('fsockopen', 'pfsockopen', 'stream_set_timeout'); $defaultMethods = array('fsockopen', 'pfsockopen', 'streamSetTimeout');
$newMethods = array_diff($methods, $defaultMethods); $newMethods = array_diff($methods, $defaultMethods);
$finalMethods = array_merge($defaultMethods, $newMethods); $finalMethods = array_merge($defaultMethods, $newMethods);
@@ -273,9 +272,9 @@ class SocketHandlerTest extends TestCase
->will($this->returnValue($this->res)); ->will($this->returnValue($this->res));
} }
if (!in_array('stream_set_timeout', $methods)) { if (!in_array('streamSetTimeout', $methods)) {
$this->handler->expects($this->any()) $this->handler->expects($this->any())
->method('stream_set_timeout') ->method('streamSetTimeout')
->will($this->returnValue(true)); ->will($this->returnValue(true));
} }