From bf0787b7cddf4a58cf1899a879f92969dfc4b489 Mon Sep 17 00:00:00 2001 From: Chris Boden Date: Thu, 10 Nov 2011 10:49:23 -0500 Subject: [PATCH] Removed Logging Removed logging - use Decorator as replacement (https://raw.github.com/cboden/RatchetApps/master/lib/RatchetApps/Logger.php) --- lib/Ratchet/Logging/LoggerInterface.php | 25 --------------- lib/Ratchet/Logging/MonologAdapter.php | 32 ------------------- lib/Ratchet/Logging/NullLogger.php | 17 ---------- lib/Ratchet/Protocol/WebSocket.php | 1 + .../Protocol/WebSocket/Version/HyBi10.php | 2 +- lib/Ratchet/Server.php | 28 +++------------- lib/Ratchet/SocketObserver.php | 1 + .../Ratchet/Tests/Logging/NullLoggerTest.php | 30 ----------------- tests/Ratchet/Tests/Mock/ArrayLogger.php | 19 ----------- tests/Ratchet/Tests/ServerTest.php | 27 ---------------- 10 files changed, 8 insertions(+), 174 deletions(-) delete mode 100644 lib/Ratchet/Logging/LoggerInterface.php delete mode 100644 lib/Ratchet/Logging/MonologAdapter.php delete mode 100644 lib/Ratchet/Logging/NullLogger.php delete mode 100644 tests/Ratchet/Tests/Logging/NullLoggerTest.php delete mode 100644 tests/Ratchet/Tests/Mock/ArrayLogger.php diff --git a/lib/Ratchet/Logging/LoggerInterface.php b/lib/Ratchet/Logging/LoggerInterface.php deleted file mode 100644 index 4b8020d..0000000 --- a/lib/Ratchet/Logging/LoggerInterface.php +++ /dev/null @@ -1,25 +0,0 @@ -addInfo($msg); - } - - /** - * Maps to Monolog\Logger::addWarning - * @param string - */ - function warning($msg) { - $this->addWarning($msg); - } - - /** - * Maps to Monolog\Logger::addError - * @param string - */ - function error($msg) { - $this->addError($msg); - } -} \ No newline at end of file diff --git a/lib/Ratchet/Logging/NullLogger.php b/lib/Ratchet/Logging/NullLogger.php deleted file mode 100644 index 78c4f9b..0000000 --- a/lib/Ratchet/Logging/NullLogger.php +++ /dev/null @@ -1,17 +0,0 @@ -_master = $host; $socket = $host->getResource(); $this->_resources[] = $socket; - if (null === $logger) { - $logger = new NullLogger; - } - $this->_log = $logger; - $this->_connections = new \ArrayIterator(array()); $this->_app = $application; @@ -61,6 +48,7 @@ class Server implements SocketObserver, \IteratorAggregate { /** * @return ArrayIterator of SocketInterfaces + * @todo This interface was originally in place as Server was passed up/down chain, but isn't anymore, consider removing */ public function getIterator() { return $this->_connections; @@ -114,7 +102,6 @@ class Server implements SocketObserver, \IteratorAggregate { } } catch (Exception $se) { // Instead of logging error, will probably add/trigger onIOError/onError or something in SocketObserver - $this->_log->error($se->getCode() . ' - ' . $se->getMessage()); // temporary, move to application if ($se->getCode() != 35) { @@ -122,7 +109,8 @@ class Server implements SocketObserver, \IteratorAggregate { $close->execute($this); } } catch (\Exception $e) { - $this->_log->error('Big uh oh: ' . $e->getMessage()); + // onError() - but can I determine which is/was the target Socket that threw the exception...? + // $conn->close() ??? } } while (true); } @@ -132,14 +120,10 @@ class Server implements SocketObserver, \IteratorAggregate { $this->_resources[] = $new_connection->getResource(); $this->_connections[$new_connection->getResource()] = $new_connection; - $this->_log->note('New connection, ' . count($this->_connections) . ' total'); - return $this->_app->onOpen($new_connection); } public function onRecv(SocketInterface $from, $msg) { -// $this->_log->note('New message "' . trim($msg) . '"'); - return $this->_app->onRecv($from, $msg); } @@ -151,8 +135,6 @@ class Server implements SocketObserver, \IteratorAggregate { unset($this->_connections[$resource]); unset($this->_resources[array_search($resource, $this->_resources)]); - $this->_log->note('Connection closed, ' . count($this->_connections) . ' connections remain'); - return $cmd; } } \ No newline at end of file diff --git a/lib/Ratchet/SocketObserver.php b/lib/Ratchet/SocketObserver.php index bbb1591..f4214da 100644 --- a/lib/Ratchet/SocketObserver.php +++ b/lib/Ratchet/SocketObserver.php @@ -5,6 +5,7 @@ namespace Ratchet; * Observable/Observer design pattern interface for handing events on a socket * @todo Consider an onException method. Since server is running its own loop the app currently doesn't know when a problem is handled * @todo Consider an onDisconnect method for a server-side close()'ing of a connection - onClose would be client side close() + * @todo Consider adding __construct(SocketObserver $decorator = null) - on Server move Socket as parameter to run() */ interface SocketObserver { /** diff --git a/tests/Ratchet/Tests/Logging/NullLoggerTest.php b/tests/Ratchet/Tests/Logging/NullLoggerTest.php deleted file mode 100644 index c46d2d4..0000000 --- a/tests/Ratchet/Tests/Logging/NullLoggerTest.php +++ /dev/null @@ -1,30 +0,0 @@ -_log = new NullLogger; - } - - public function testInterface() { - $this->assertInstanceOf('\\Ratchet\\Logging\\LoggerInterface', $this->_log); - } - - public function testNoteDoesNothing() { - $this->assertNull($this->_log->note('hi')); - } - - public function testWarningDoesNothing() { - $this->assertNull($this->_log->warning('hi')); - } - - public function testErrorDoesNothing() { - $this->assertNull($this->_log->error('hi')); - } -} \ No newline at end of file diff --git a/tests/Ratchet/Tests/Mock/ArrayLogger.php b/tests/Ratchet/Tests/Mock/ArrayLogger.php deleted file mode 100644 index 5b047a5..0000000 --- a/tests/Ratchet/Tests/Mock/ArrayLogger.php +++ /dev/null @@ -1,19 +0,0 @@ -last_msg = $msg; - } - - public function warning($msg) { - $this->last_msg = $msg; - } - - public function error($msg) { - $this->last_msg = $msg; - } -} \ No newline at end of file diff --git a/tests/Ratchet/Tests/ServerTest.php b/tests/Ratchet/Tests/ServerTest.php index 1f7ea82..9111364 100644 --- a/tests/Ratchet/Tests/ServerTest.php +++ b/tests/Ratchet/Tests/ServerTest.php @@ -3,7 +3,6 @@ namespace Ratchet\Tests; use Ratchet\Server; use Ratchet\Tests\Mock\FakeSocket as Socket; use Ratchet\Tests\Mock\Application as TestApp; -use Ratchet\Tests\Mock\ArrayLogger; /** * @covers Ratchet\Server @@ -32,32 +31,6 @@ class ServerTest extends \PHPUnit_Framework_TestCase { $this->assertThat($this->_server, $constraint); } - public function testNullLoggerIsSetInConstruct() { - $this->assertInstanceOf('\\Ratchet\\Logging\\LoggerInterface', $this->getPrivateProperty($this->_server, '_log')); - } - - public function testPassedLoggerIsSetInConstruct() { - $logger = new ArrayLogger; - $server = new Server(new Socket(), $this->_app, $logger); - - $this->assertSame($logger, $this->getPrivateProperty($server, '_log')); - } - -/* - public function testLoggerIsSetInMethod() { - $logger = new ArrayLogger; - $this->_server->setLogger($logger); - - $this->assertSame($logger, $this->getPrivateProperty($this->_server, '_log')); - } -*/ - -/* - public function testGetMasterReturnsCatalyst() { - $this->assertSame($this->_catalyst, $this->_server->getMaster()); - } -*/ - public function testIteration() { $this->assertInstanceOf('\\Iterator', $this->_server->getIterator()); }