diff --git a/lib/ext/Syncroton/Server.php b/lib/ext/Syncroton/Server.php --- a/lib/ext/Syncroton/Server.php +++ b/lib/ext/Syncroton/Server.php @@ -123,8 +123,7 @@ $decoder = new Syncroton_Wbxml_Decoder($this->_body); $requestBody = $decoder->decode(); if ($this->_logger instanceof Zend_Log) { - $requestBody->formatOutput = true; - $this->_logger->debug(__METHOD__ . '::' . __LINE__ . " xml request:\n" . $requestBody->saveXML()); + $this->_logDomDocument($requestBody, 'request', __METHOD__, __LINE__); } } catch(Syncroton_Wbxml_Exception_UnexpectedEndOfFile $e) { if ($this->_logger instanceof Zend_Log) @@ -176,7 +175,7 @@ if ($response instanceof DOMDocument) { if ($this->_logger instanceof Zend_Log) { - $this->_logDomDocument(Zend_Log::DEBUG, $response, __METHOD__, __LINE__); + $this->_logDomDocument($response, 'response', __METHOD__, __LINE__); } if (isset($command) && $command instanceof Syncroton_Command_ICommand) { @@ -246,13 +245,17 @@ /** * write (possible big) DOMDocument in smaller chunks to log file * - * @param int $priority * @param DOMDocument $dom + * @param string $action * @param string $method * @param int $line */ - protected function _logDomDocument($priority, DOMDocument $dom, $method, $line) + protected function _logDomDocument(DOMDocument $dom, $action, $method, $line) { + if (method_exists($this->_logger, 'hasDebug') && !$this->_logger->hasDebug()) { + return; + } + $tempStream = tmpfile(); $meta_data = stream_get_meta_data($tempStream); @@ -266,7 +269,7 @@ $loops = 0; while (!feof($tempStream)) { - $this->_logger->log($method . '::' . $line . " xml response($loops):\n" . fread($tempStream, 1048576), $priority); + $this->_logger->debug("{$method}::{$line} xml {$action} ({$loops}):\n" . fread($tempStream, 1048576)); $loops++; } diff --git a/lib/kolab_sync_logger.php b/lib/kolab_sync_logger.php --- a/lib/kolab_sync_logger.php +++ b/lib/kolab_sync_logger.php @@ -59,6 +59,17 @@ } /** + * Check whether debug logging is enabled + * + * @return bool + */ + public function hasDebug() + { + // This is what we check in self::log() below + return !empty($this->log_dir) && $this->mode >= self::NOTICE; + } + + /** * Message logger * * @param string $message Log message