diff --git a/lib/Ratchet/Logging/LoggerInterface.php b/lib/Ratchet/Logging/LoggerInterface.php new file mode 100644 index 0000000..8c0e01f --- /dev/null +++ b/lib/Ratchet/Logging/LoggerInterface.php @@ -0,0 +1,19 @@ +addInfo($msg); + } + + function warning($msg) { + $this->addWarning($msg); + } + + 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 new file mode 100644 index 0000000..3e92ed3 --- /dev/null +++ b/lib/Ratchet/Logging/NullLogger.php @@ -0,0 +1,13 @@ +_master = $host; - $socket = $host->getResource(); - $this->_resources[] = $socket; + + if (null === $logger) { + $logger = new NullLogger; + } + $this->_log = $logger; + } + + public function setLogger(LoggerInterface $logger) { + $this->_log = $logger; } /** @@ -110,12 +128,15 @@ class Server implements ServerInterface { $this->_resources[] = $new_connection->getResource(); $this->_connections[$new_connection->getResource()] = $new_connection; + $this->_log->note('New connection, ' . count($this->_connections) . ' total'); + // /here $this->_receivers->handleConnection($new_connection); $this->tmpRIterator('handleConnect', $new_connection); } protected function onMessage($msg, Socket $from) { - $this->tmpRIterator('handleMessage', $data, $conn); + $this->_log->note('New message "' . trim($msg) . '"'); + $this->tmpRIterator('handleMessage', $msg, $from); } protected function onClose(Socket $conn) { @@ -125,6 +146,8 @@ class Server implements ServerInterface { unset($this->_connections[$resource]); unset($this->_resources[array_search($resource, $this->_resources)]); + + $this->_log->note('Connection closed, ' . count($this->_connections) . ' connections remain (' . count($this->_resources) . ')'); } protected function tmpRIterator() {