summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2018-01-23 11:56:02 +0100
committerGitHub <noreply@github.com>2018-01-23 11:56:02 +0100
commit4537faa5dabdcb2f0b888baa5031e59099e52d6a (patch)
tree0295177ddd5f6736739c503131eb75323561b220 /lib
parent9cb3a79b18bb74e3f79d53aa400d7efa5b2c2174 (diff)
parent2a38605545e26ce68a37e5ebb877fd9c9875a37d (diff)
downloadnextcloud-server-4537faa5dabdcb2f0b888baa5031e59099e52d6a.tar.gz
nextcloud-server-4537faa5dabdcb2f0b888baa5031e59099e52d6a.zip
Merge pull request #7918 from nextcloud/properly-log-exceptions
Properly log the full exception instead of only the message
Diffstat (limited to 'lib')
-rw-r--r--lib/base.php6
-rw-r--r--lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php5
-rw-r--r--lib/private/CapabilitiesManager.php6
-rw-r--r--lib/private/Files/Cache/Scanner.php6
-rw-r--r--lib/private/Files/ObjectStore/S3ConnectionTrait.php6
-rw-r--r--lib/private/Files/Storage/DAV.php3
-rw-r--r--lib/private/Files/Storage/Wrapper/Encryption.php7
-rw-r--r--lib/private/Files/View.php11
-rw-r--r--lib/private/Installer.php5
-rw-r--r--lib/private/Preview/Bitmap.php6
-rw-r--r--lib/private/Preview/Office.php5
-rw-r--r--lib/private/Preview/SVG.php5
-rw-r--r--lib/private/Setup/MySQL.php24
-rw-r--r--lib/private/Tags.php105
14 files changed, 141 insertions, 59 deletions
diff --git a/lib/base.php b/lib/base.php
index 99651479dfa..6e66005b28f 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -809,7 +809,11 @@ class OC {
} catch (\Exception $e) {
// a GC exception should not prevent users from using OC,
// so log the exception
- \OC::$server->getLogger()->warning('Exception when running cache gc: ' . $e->getMessage(), array('app' => 'core'));
+ \OC::$server->getLogger()->logException($e, [
+ 'message' => 'Exception when running cache gc.',
+ 'level' => \OCP\Util::WARN,
+ 'app' => 'core',
+ ]);
}
});
}
diff --git a/lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php b/lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php
index c147b5b2475..1c049fb3621 100644
--- a/lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php
+++ b/lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php
@@ -252,7 +252,10 @@ class SecurityMiddleware extends Middleware {
}
}
- $this->logger->debug($exception->getMessage());
+ $this->logger->logException($exception, [
+ 'level' => \OCP\Util::DEBUG,
+ 'app' => 'core',
+ ]);
return $response;
}
diff --git a/lib/private/CapabilitiesManager.php b/lib/private/CapabilitiesManager.php
index fc8f14a7a83..fb272764597 100644
--- a/lib/private/CapabilitiesManager.php
+++ b/lib/private/CapabilitiesManager.php
@@ -55,7 +55,11 @@ class CapabilitiesManager {
try {
$c = $capability();
} catch (QueryException $e) {
- $this->logger->error('CapabilitiesManager: {message}', ['app' => 'core', 'message' => $e->getMessage()]);
+ $this->logger->logException($e, [
+ 'message' => 'CapabilitiesManager',
+ 'level' => \OCP\Util::ERROR,
+ 'app' => 'core',
+ ]);
continue;
}
diff --git a/lib/private/Files/Cache/Scanner.php b/lib/private/Files/Cache/Scanner.php
index 85a89962f76..28a3d11ffa9 100644
--- a/lib/private/Files/Cache/Scanner.php
+++ b/lib/private/Files/Cache/Scanner.php
@@ -452,7 +452,11 @@ class Scanner extends BasicEmitter implements IScanner {
\OC::$server->getDatabaseConnection()->rollback();
\OC::$server->getDatabaseConnection()->beginTransaction();
}
- \OCP\Util::writeLog('core', 'Exception while scanning file "' . $child . '": ' . $ex->getMessage(), \OCP\Util::DEBUG);
+ \OC::$server->getLogger()->logException($ex, [
+ 'message' => 'Exception while scanning file "' . $child . '"',
+ 'level' => \OCP\Util::DEBUG,
+ 'app' => 'core',
+ ]);
$exceptionOccurred = true;
} catch (\OCP\Lock\LockedException $e) {
if ($this->useTransactions) {
diff --git a/lib/private/Files/ObjectStore/S3ConnectionTrait.php b/lib/private/Files/ObjectStore/S3ConnectionTrait.php
index d4910834962..7e70cc846ef 100644
--- a/lib/private/Files/ObjectStore/S3ConnectionTrait.php
+++ b/lib/private/Files/ObjectStore/S3ConnectionTrait.php
@@ -109,7 +109,11 @@ trait S3ConnectionTrait {
));
$this->testTimeout();
} catch (S3Exception $e) {
- \OCP\Util::logException('files_external', $e);
+ \OC::$server->getLogger()->logException($e, [
+ 'message' => 'Invalid remote storage.',
+ 'level' => \OCP\Util::DEBUG,
+ 'app' => 'files_external',
+ ]);
throw new \Exception('Creation of bucket failed. ' . $e->getMessage());
}
}
diff --git a/lib/private/Files/Storage/DAV.php b/lib/private/Files/Storage/DAV.php
index 6585dd862e4..43347aa0b8f 100644
--- a/lib/private/Files/Storage/DAV.php
+++ b/lib/private/Files/Storage/DAV.php
@@ -830,8 +830,7 @@ class DAV extends Common {
* which might be temporary
*/
protected function convertException(Exception $e, $path = '') {
- \OC::$server->getLogger()->logException($e);
- Util::writeLog('files_external', $e->getMessage(), Util::ERROR);
+ \OC::$server->getLogger()->logException($e, ['app' => 'files_external']);
if ($e instanceof ClientHttpException) {
if ($e->getHttpStatus() === Http::STATUS_LOCKED) {
throw new \OCP\Lock\LockedException($path);
diff --git a/lib/private/Files/Storage/Wrapper/Encryption.php b/lib/private/Files/Storage/Wrapper/Encryption.php
index 1ca750f0024..d443ccfd49b 100644
--- a/lib/private/Files/Storage/Wrapper/Encryption.php
+++ b/lib/private/Files/Storage/Wrapper/Encryption.php
@@ -441,8 +441,11 @@ class Encryption extends Wrapper {
}
}
} catch (ModuleDoesNotExistsException $e) {
- $this->logger->warning('Encryption module "' . $encryptionModuleId .
- '" not found, file will be stored unencrypted (' . $e->getMessage() . ')');
+ $this->logger->logException($e, [
+ 'message' => 'Encryption module "' . $encryptionModuleId . '" not found, file will be stored unencrypted',
+ 'level' => \OCP\Util::WARN,
+ 'app' => 'core',
+ ]);
}
// encryption disabled on write of new file and write to existing unencrypted file -> don't encrypt
diff --git a/lib/private/Files/View.php b/lib/private/Files/View.php
index 592d4b717ce..fb0b116666e 100644
--- a/lib/private/Files/View.php
+++ b/lib/private/Files/View.php
@@ -1464,12 +1464,11 @@ class View {
continue;
} catch (\Exception $e) {
// sometimes when the storage is not available it can be any exception
- \OCP\Util::writeLog(
- 'core',
- 'Exception while scanning storage "' . $subStorage->getId() . '": ' .
- get_class($e) . ': ' . $e->getMessage(),
- \OCP\Util::ERROR
- );
+ \OC::$server->getLogger()->logException($e, [
+ 'message' => 'Exception while scanning storage "' . $subStorage->getId() . '"',
+ 'level' => \OCP\Util::ERROR,
+ 'app' => 'lib',
+ ]);
continue;
}
$rootEntry = $subCache->get('');
diff --git a/lib/private/Installer.php b/lib/private/Installer.php
index 1c6c3915b41..ed654c2b241 100644
--- a/lib/private/Installer.php
+++ b/lib/private/Installer.php
@@ -195,7 +195,10 @@ class Installer {
try {
$this->downloadApp($appId);
} catch (\Exception $e) {
- $this->logger->error($e->getMessage(), ['app' => 'core']);
+ $this->logger->logException($e, [
+ 'level' => \OCP\Util::ERROR,
+ 'app' => 'core',
+ ]);
return false;
}
return OC_App::updateApp($appId);
diff --git a/lib/private/Preview/Bitmap.php b/lib/private/Preview/Bitmap.php
index a375717480a..ff6093fcf81 100644
--- a/lib/private/Preview/Bitmap.php
+++ b/lib/private/Preview/Bitmap.php
@@ -48,7 +48,11 @@ abstract class Bitmap extends Provider {
try {
$bp = $this->getResizedPreview($tmpPath, $maxX, $maxY);
} catch (\Exception $e) {
- \OCP\Util::writeLog('core', 'ImageMagick says: ' . $e->getMessage(), \OCP\Util::ERROR);
+ \OC::$server->getLogger()->logException($e, [
+ 'message' => 'Imagick says:',
+ 'level' => \OCP\Util::ERROR,
+ 'app' => 'core',
+ ]);
return false;
}
diff --git a/lib/private/Preview/Office.php b/lib/private/Preview/Office.php
index 2ec677c04fe..6403cf5dd8d 100644
--- a/lib/private/Preview/Office.php
+++ b/lib/private/Preview/Office.php
@@ -59,7 +59,10 @@ abstract class Office extends Provider {
} catch (\Exception $e) {
unlink($absPath);
unlink($pdfPreview);
- \OCP\Util::writeLog('core', $e->getMessage(), \OCP\Util::ERROR);
+ \OC::$server->getLogger()->logException($e, [
+ 'level' => \OCP\Util::ERROR,
+ 'app' => 'core',
+ ]);
return false;
}
diff --git a/lib/private/Preview/SVG.php b/lib/private/Preview/SVG.php
index 0695c251c8b..e0abf04d931 100644
--- a/lib/private/Preview/SVG.php
+++ b/lib/private/Preview/SVG.php
@@ -53,7 +53,10 @@ class SVG extends Provider {
$svg->readImageBlob($content);
$svg->setImageFormat('png32');
} catch (\Exception $e) {
- \OCP\Util::writeLog('core', $e->getMessage(), \OCP\Util::ERROR);
+ \OC::$server->getLogger()->logException($e, [
+ 'level' => \OCP\Util::ERROR,
+ 'app' => 'core',
+ ]);
return false;
}
diff --git a/lib/private/Setup/MySQL.php b/lib/private/Setup/MySQL.php
index 30163f03659..9d80bd49aed 100644
--- a/lib/private/Setup/MySQL.php
+++ b/lib/private/Setup/MySQL.php
@@ -68,9 +68,10 @@ class MySQL extends AbstractDatabase {
$query = "CREATE DATABASE IF NOT EXISTS `$name` CHARACTER SET $characterSet COLLATE ${characterSet}_bin;";
$connection->executeUpdate($query);
} catch (\Exception $ex) {
- $this->logger->error('Database creation failed: {error}', [
+ $this->logger->logException($ex, [
+ 'message' => 'Database creation failed.',
+ 'level' => \OCP\Util::ERROR,
'app' => 'mysql.setup',
- 'error' => $ex->getMessage()
]);
return;
}
@@ -80,9 +81,10 @@ class MySQL extends AbstractDatabase {
$query="GRANT ALL PRIVILEGES ON `$name` . * TO '$user'";
$connection->executeUpdate($query);
} catch (\Exception $ex) {
- $this->logger->debug('Could not automatically grant privileges, this can be ignored if database user already had privileges: {error}', [
+ $this->logger->logException($ex, [
+ 'message' => 'Could not automatically grant privileges, this can be ignored if database user already had privileges.',
+ 'level' => \OCP\Util::DEBUG,
'app' => 'mysql.setup',
- 'error' => $ex->getMessage()
]);
}
}
@@ -103,10 +105,11 @@ class MySQL extends AbstractDatabase {
$connection->executeUpdate($query);
}
catch (\Exception $ex){
- $this->logger->error('Database User creation failed: {error}', [
- 'app' => 'mysql.setup',
- 'error' => $ex->getMessage()
- ]);
+ $this->logger->logException($ex, [
+ 'message' => 'Database user creation failed.',
+ 'level' => \OCP\Util::ERROR,
+ 'app' => 'mysql.setup',
+ ]);
}
}
@@ -157,9 +160,10 @@ class MySQL extends AbstractDatabase {
};
}
} catch (\Exception $ex) {
- $this->logger->info('Can not create a new MySQL user, will continue with the provided user: {error}', [
+ $this->logger->logException($ex, [
+ 'message' => 'Can not create a new MySQL user, will continue with the provided user.',
+ 'level' => \OCP\Util::INFO,
'app' => 'mysql.setup',
- 'error' => $ex->getMessage()
]);
}
diff --git a/lib/private/Tags.php b/lib/private/Tags.php
index 2ac70484843..1b3505da5bd 100644
--- a/lib/private/Tags.php
+++ b/lib/private/Tags.php
@@ -242,8 +242,11 @@ class Tags implements \OCP\ITags {
}
}
} catch(\Exception $e) {
- \OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
- \OCP\Util::ERROR);
+ \OC::$server->getLogger()->logException($e, [
+ 'message' => __METHOD__,
+ 'level' => \OCP\Util::ERROR,
+ 'app' => 'core',
+ ]);
return false;
}
@@ -292,8 +295,11 @@ class Tags implements \OCP\ITags {
return false;
}
} catch(\Exception $e) {
- \OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
- \OCP\Util::ERROR);
+ \OC::$server->getLogger()->logException($e, [
+ 'message' => __METHOD__,
+ 'level' => \OCP\Util::ERROR,
+ 'app' => 'core',
+ ]);
return false;
}
@@ -366,8 +372,11 @@ class Tags implements \OCP\ITags {
$tag = $this->mapper->insert($tag);
$this->tags[] = $tag;
} catch(\Exception $e) {
- \OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
- \OCP\Util::ERROR);
+ \OC::$server->getLogger()->logException($e, [
+ 'message' => __METHOD__,
+ 'level' => \OCP\Util::ERROR,
+ 'app' => 'core',
+ ]);
return false;
}
\OCP\Util::writeLog('core', __METHOD__.', id: ' . $tag->getId(), \OCP\Util::DEBUG);
@@ -410,8 +419,11 @@ class Tags implements \OCP\ITags {
$tag->setName($to);
$this->tags[$key] = $this->mapper->update($tag);
} catch(\Exception $e) {
- \OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
- \OCP\Util::ERROR);
+ \OC::$server->getLogger()->logException($e, [
+ 'message' => __METHOD__,
+ 'level' => \OCP\Util::ERROR,
+ 'app' => 'core',
+ ]);
return false;
}
return true;
@@ -462,8 +474,11 @@ class Tags implements \OCP\ITags {
$this->mapper->insert($tag);
}
} catch(\Exception $e) {
- \OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
- \OCP\Util::ERROR);
+ \OC::$server->getLogger()->logException($e, [
+ 'message' => __METHOD__,
+ 'level' => \OCP\Util::ERROR,
+ 'app' => 'core',
+ ]);
}
}
@@ -488,8 +503,11 @@ class Tags implements \OCP\ITags {
'type' => $this->type,
));
} catch(\Exception $e) {
- \OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
- \OCP\Util::ERROR);
+ \OC::$server->getLogger()->logException($e, [
+ 'message' => __METHOD__,
+ 'level' => \OCP\Util::ERROR,
+ 'app' => 'core',
+ ]);
}
}
}
@@ -518,8 +536,11 @@ class Tags implements \OCP\ITags {
\OCP\Util::writeLog('core', __METHOD__. 'DB error: ' . \OCP\DB::getErrorMessage(), \OCP\Util::ERROR);
}
} catch(\Exception $e) {
- \OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
- \OCP\Util::ERROR);
+ \OC::$server->getLogger()->logException($e, [
+ 'message' => __METHOD__,
+ 'level' => \OCP\Util::ERROR,
+ 'app' => 'core',
+ ]);
}
if(!is_null($result)) {
@@ -530,13 +551,19 @@ class Tags implements \OCP\ITags {
try {
$stmt->execute(array($row['id']));
} catch(\Exception $e) {
- \OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
- \OCP\Util::ERROR);
+ \OC::$server->getLogger()->logException($e, [
+ 'message' => __METHOD__,
+ 'level' => \OCP\Util::ERROR,
+ 'app' => 'core',
+ ]);
}
}
} catch(\Exception $e) {
- \OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
- \OCP\Util::ERROR);
+ \OC::$server->getLogger()->logException($e, [
+ 'message' => __METHOD__,
+ 'level' => \OCP\Util::ERROR,
+ 'app' => 'core',
+ ]);
}
}
try {
@@ -547,8 +574,11 @@ class Tags implements \OCP\ITags {
\OCP\Util::writeLog('core', __METHOD__. ', DB error: ' . \OCP\DB::getErrorMessage(), \OCP\Util::ERROR);
}
} catch(\Exception $e) {
- \OCP\Util::writeLog('core', __METHOD__ . ', exception: '
- . $e->getMessage(), \OCP\Util::ERROR);
+ \OC::$server->getLogger()->logException($e, [
+ 'message' => __METHOD__,
+ 'level' => \OCP\Util::ERROR,
+ 'app' => 'core',
+ ]);
}
}
@@ -576,8 +606,11 @@ class Tags implements \OCP\ITags {
return false;
}
} catch(\Exception $e) {
- \OCP\Util::writeLog('core', __METHOD__.', exception: ' . $e->getMessage(),
- \OCP\Util::ERROR);
+ \OC::$server->getLogger()->logException($e, [
+ 'message' => __METHOD__,
+ 'level' => \OCP\Util::ERROR,
+ 'app' => 'core',
+ ]);
return false;
}
return true;
@@ -592,8 +625,11 @@ class Tags implements \OCP\ITags {
try {
return $this->getIdsForTag(self::TAG_FAVORITE);
} catch(\Exception $e) {
- \OCP\Util::writeLog('core', __METHOD__.', exception: ' . $e->getMessage(),
- \OCP\Util::DEBUG);
+ \OC::$server->getLogger()->logException($e, [
+ 'message' => __METHOD__,
+ 'level' => \OCP\Util::ERROR,
+ 'app' => 'core',
+ ]);
return array();
}
}
@@ -650,8 +686,11 @@ class Tags implements \OCP\ITags {
'type' => $this->type,
));
} catch(\Exception $e) {
- \OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
- \OCP\Util::ERROR);
+ \OC::$server->getLogger()->logException($e, [
+ 'message' => __METHOD__,
+ 'level' => \OCP\Util::ERROR,
+ 'app' => 'core',
+ ]);
return false;
}
return true;
@@ -682,8 +721,11 @@ class Tags implements \OCP\ITags {
$stmt = \OCP\DB::prepare($sql);
$stmt->execute(array($objid, $tagId, $this->type));
} catch(\Exception $e) {
- \OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
- \OCP\Util::ERROR);
+ \OC::$server->getLogger()->logException($e, [
+ 'message' => __METHOD__,
+ 'level' => \OCP\Util::ERROR,
+ 'app' => 'core',
+ ]);
return false;
}
return true;
@@ -735,8 +777,11 @@ class Tags implements \OCP\ITags {
return false;
}
} catch(\Exception $e) {
- \OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
- \OCP\Util::ERROR);
+ \OC::$server->getLogger()->logException($e, [
+ 'message' => __METHOD__,
+ 'level' => \OCP\Util::ERROR,
+ 'app' => 'core',
+ ]);
return false;
}
}