summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2017-04-26 22:58:01 -0300
committerGitHub <noreply@github.com>2017-04-26 22:58:01 -0300
commit01705b1b6a500199796c1d289ae8dd7363c27383 (patch)
treee647526349c54a1d008691b2af0ed95112816220 /lib/private
parent0ac806a9dd69eee2ef80bb4d256d3a1355dd36f3 (diff)
parentd0bbae7425e8a39788222dcaab17466c24c3c089 (diff)
downloadnextcloud-server-01705b1b6a500199796c1d289ae8dd7363c27383.tar.gz
nextcloud-server-01705b1b6a500199796c1d289ae8dd7363c27383.zip
Merge pull request #4515 from nextcloud/downstream-27643
Adjust query/event logging code in favour of more complex owncloud/di…
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/DB/Connection.php3
-rw-r--r--lib/private/Diagnostics/EventLogger.php39
-rw-r--r--lib/private/Diagnostics/NullEventLogger.php58
-rw-r--r--lib/private/Diagnostics/NullQueryLogger.php46
-rw-r--r--lib/private/Diagnostics/Query.php9
-rw-r--r--lib/private/Diagnostics/QueryLogger.php29
-rw-r--r--lib/private/Server.php15
-rw-r--r--lib/private/legacy/db/statementwrapper.php9
8 files changed, 73 insertions, 135 deletions
diff --git a/lib/private/DB/Connection.php b/lib/private/DB/Connection.php
index 9e116712642..6b56ae8ad5c 100644
--- a/lib/private/DB/Connection.php
+++ b/lib/private/DB/Connection.php
@@ -167,9 +167,6 @@ class Connection extends \Doctrine\DBAL\Connection implements IDBConnection {
$statement = $this->replaceTablePrefix($statement);
$statement = $this->adapter->fixupStatement($statement);
- if(\OC::$server->getSystemConfig()->getValue( 'log_query', false)) {
- \OCP\Util::writeLog('core', 'DB prepare : '.$statement, \OCP\Util::DEBUG);
- }
return parent::prepare($statement);
}
diff --git a/lib/private/Diagnostics/EventLogger.php b/lib/private/Diagnostics/EventLogger.php
index 5abaae3f1dd..846be7efc5b 100644
--- a/lib/private/Diagnostics/EventLogger.php
+++ b/lib/private/Diagnostics/EventLogger.php
@@ -4,6 +4,8 @@
*
* @author Morris Jobke <hey@morrisjobke.de>
* @author Robin Appelman <robin@icewind.nl>
+ * @author Thomas Müller <thomas.mueller@tmit.eu>
+ * @author Piotr Mrowczynski <piotr@owncloud.com>
*
* @license AGPL-3.0
*
@@ -29,28 +31,53 @@ class EventLogger implements IEventLogger {
/**
* @var \OC\Diagnostics\Event[]
*/
- private $events = array();
+ private $events = [];
+
+ /**
+ * @var bool - Module needs to be activated by some app
+ */
+ private $activated = false;
+ /**
+ * @inheritdoc
+ */
public function start($id, $description) {
- $this->events[$id] = new Event($id, $description, microtime(true));
+ if ($this->activated){
+ $this->events[$id] = new Event($id, $description, microtime(true));
+ }
}
+ /**
+ * @inheritdoc
+ */
public function end($id) {
- if (isset($this->events[$id])) {
+ if ($this->activated && isset($this->events[$id])) {
$timing = $this->events[$id];
$timing->end(microtime(true));
}
}
+ /**
+ * @inheritdoc
+ */
public function log($id, $description, $start, $end) {
- $this->events[$id] = new Event($id, $description, $start);
- $this->events[$id]->end($end);
+ if ($this->activated) {
+ $this->events[$id] = new Event($id, $description, $start);
+ $this->events[$id]->end($end);
+ }
}
/**
- * @return \OCP\Diagnostics\IEvent[]
+ * @inheritdoc
*/
public function getEvents() {
return $this->events;
}
+
+ /**
+ * @inheritdoc
+ */
+ public function activate() {
+ $this->activated = true;
+ }
}
diff --git a/lib/private/Diagnostics/NullEventLogger.php b/lib/private/Diagnostics/NullEventLogger.php
deleted file mode 100644
index 9fe7461eb45..00000000000
--- a/lib/private/Diagnostics/NullEventLogger.php
+++ /dev/null
@@ -1,58 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Robin Appelman <robin@icewind.nl>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-
-namespace OC\Diagnostics;
-
-use OCP\Diagnostics\IEventLogger;
-
-/**
- * Dummy event logger that doesn't actually log anything
- */
-class NullEventLogger implements IEventLogger {
- /**
- * Mark the start of an event
- *
- * @param $id
- * @param $description
- */
- public function start($id, $description) {
- }
-
- /**
- * Mark the end of an event
- *
- * @param $id
- */
- public function end($id) {
- }
-
- public function log($id, $description, $start, $end) {
- }
-
- /**
- * @return \OCP\Diagnostics\IEvent[]
- */
- public function getEvents() {
- return array();
- }
-}
diff --git a/lib/private/Diagnostics/NullQueryLogger.php b/lib/private/Diagnostics/NullQueryLogger.php
deleted file mode 100644
index 873f556f90e..00000000000
--- a/lib/private/Diagnostics/NullQueryLogger.php
+++ /dev/null
@@ -1,46 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Robin Appelman <robin@icewind.nl>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-
-namespace OC\Diagnostics;
-
-use OCP\Diagnostics\IQueryLogger;
-
-class NullQueryLogger implements IQueryLogger {
- /**
- * @param string $sql
- * @param array $params
- * @param array $types
- */
- public function startQuery($sql, array $params = null, array $types = null) {
- }
-
- public function stopQuery() {
- }
-
- /**
- * @return \OCP\Diagnostics\IQuery[]
- */
- public function getQueries() {
- return array();
- }
-}
diff --git a/lib/private/Diagnostics/Query.php b/lib/private/Diagnostics/Query.php
index 8ac2cc0eeac..7b083ed41b7 100644
--- a/lib/private/Diagnostics/Query.php
+++ b/lib/private/Diagnostics/Query.php
@@ -67,7 +67,14 @@ class Query implements IQuery {
}
/**
- * @return int
+ * @return float
+ */
+ public function getStart() {
+ return $this->start;
+ }
+
+ /**
+ * @return float
*/
public function getDuration() {
return $this->end - $this->start;
diff --git a/lib/private/Diagnostics/QueryLogger.php b/lib/private/Diagnostics/QueryLogger.php
index 5f2a061a910..875d25e9be3 100644
--- a/lib/private/Diagnostics/QueryLogger.php
+++ b/lib/private/Diagnostics/QueryLogger.php
@@ -4,6 +4,8 @@
*
* @author Morris Jobke <hey@morrisjobke.de>
* @author Robin Appelman <robin@icewind.nl>
+ * @author Thomas Müller <thomas.mueller@tmit.eu>
+ * @author Piotr Mrowczynski <piotr@owncloud.com>
*
* @license AGPL-3.0
*
@@ -46,12 +48,17 @@ class QueryLogger implements IQueryLogger {
/**
- * @param string $sql
- * @param array $params
- * @param array $types
+ * @var bool - Module needs to be activated by some app
+ */
+ private $activated = false;
+
+ /**
+ * @inheritdoc
*/
public function startQuery($sql, array $params = null, array $types = null) {
- $this->activeQuery = new Query($sql, $params, microtime(true), $this->getStack());
+ if ($this->activated) {
+ $this->activeQuery = new Query($sql, $params, microtime(true), $this->getStack());
+ }
}
private function getStack() {
@@ -62,8 +69,11 @@ class QueryLogger implements IQueryLogger {
return $stack;
}
+ /**
+ * @inheritdoc
+ */
public function stopQuery() {
- if ($this->activeQuery) {
+ if ($this->activated && $this->activeQuery) {
$this->activeQuery->end(microtime(true));
$this->queries[] = $this->activeQuery;
$this->activeQuery = null;
@@ -71,9 +81,16 @@ class QueryLogger implements IQueryLogger {
}
/**
- * @return Query[]
+ * @inheritdoc
*/
public function getQueries() {
return $this->queries->getData();
}
+
+ /**
+ * @inheritdoc
+ */
+ public function activate() {
+ $this->activated = true;
+ }
}
diff --git a/lib/private/Server.php b/lib/private/Server.php
index b05e05660b0..25c0b5d9cc9 100644
--- a/lib/private/Server.php
+++ b/lib/private/Server.php
@@ -603,22 +603,23 @@ class Server extends ServerContainer implements IServerContainer {
);
});
$this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class);
-
$this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) {
+ $eventLogger = new EventLogger();
if ($c->getSystemConfig()->getValue('debug', false)) {
- return new EventLogger();
- } else {
- return new NullEventLogger();
+ // In debug mode, module is being activated by default
+ $eventLogger->activate();
}
+ return $eventLogger;
});
$this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class);
$this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) {
+ $queryLogger = new QueryLogger();
if ($c->getSystemConfig()->getValue('debug', false)) {
- return new QueryLogger();
- } else {
- return new NullQueryLogger();
+ // In debug mode, module is being activated by default
+ $queryLogger->activate();
}
+ return $queryLogger;
});
$this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class);
diff --git a/lib/private/legacy/db/statementwrapper.php b/lib/private/legacy/db/statementwrapper.php
index dedaf2d8cef..53f7b484d04 100644
--- a/lib/private/legacy/db/statementwrapper.php
+++ b/lib/private/legacy/db/statementwrapper.php
@@ -64,14 +64,7 @@ class OC_DB_StatementWrapper {
* @param array $input
* @return \OC_DB_StatementWrapper|int
*/
- public function execute($input=array()) {
- if(\OC::$server->getSystemConfig()->getValue( "log_query", false)) {
- $backTrace = debug_backtrace();
- $class = $backTrace[1]['class'] . ':' . $backTrace[1]['function'];
- $file = substr($backTrace[0]['file'], strlen(\OC::$SERVERROOT)) . ':' . $backTrace[0]['line'];
- $params_str = str_replace("\n", " ", var_export($input, true));
- \OCP\Util::writeLog('core', "DB execute with arguments : $params_str in $class; $file", \OCP\Util::DEBUG);
- }
+ public function execute($input= []) {
$this->lastArguments = $input;
if (count($input) > 0) {
$result = $this->statement->execute($input);