Merge pull request #7918 from nextcloud/properly-log-exceptions

Properly log the full exception instead of only the message
This commit is contained in:
Roeland Jago Douma 2018-01-23 11:56:02 +01:00 committed by GitHub
commit 4537faa5da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
37 changed files with 321 additions and 149 deletions

View File

@ -372,11 +372,11 @@ class KeyManager {
} catch (DecryptionFailedException $e) { } catch (DecryptionFailedException $e) {
return false; return false;
} catch (\Exception $e) { } catch (\Exception $e) {
$this->log->warning( $this->log->logException($e, [
'Could not decrypt the private key from user "' . $uid . '"" during login. ' . 'message' => 'Could not decrypt the private key from user "' . $uid . '"" during login. Assume password change on the user back-end.',
'Assume password change on the user back-end. Error message: ' 'level' => \OCP\Util::WARN,
. $e->getMessage() 'app' => 'encryption',
); ]);
return false; return false;
} }

View File

@ -164,6 +164,10 @@ class MountPublicLinkController extends Controller {
try { try {
$this->federatedShareProvider->create($share); $this->federatedShareProvider->create($share);
} catch (\Exception $e) { } catch (\Exception $e) {
\OC::$server->getLogger()->logException($e, [
'level' => \OCP\Util::WARN,
'app' => 'federatedfilesharing',
]);
return new JSONResponse(['message' => $e->getMessage()], Http::STATUS_BAD_REQUEST); return new JSONResponse(['message' => $e->getMessage()], Http::STATUS_BAD_REQUEST);
} }
@ -286,18 +290,18 @@ class MountPublicLinkController extends Controller {
$storage->checkStorageAvailability(); $storage->checkStorageAvailability();
} catch (StorageInvalidException $e) { } catch (StorageInvalidException $e) {
// note: checkStorageAvailability will already remove the invalid share // note: checkStorageAvailability will already remove the invalid share
Util::writeLog( \OC::$server->getLogger()->logException($e, [
'federatedfilesharing', 'message' => 'Invalid remote storage.',
'Invalid remote storage: ' . get_class($e) . ': ' . $e->getMessage(), 'level' => \OCP\Util::DEBUG,
Util::DEBUG 'app' => 'federatedfilesharing'
); ]);
return new JSONResponse(['message' => $this->l->t('Could not authenticate to remote share, password might be wrong')], Http::STATUS_BAD_REQUEST); return new JSONResponse(['message' => $this->l->t('Could not authenticate to remote share, password might be wrong')], Http::STATUS_BAD_REQUEST);
} catch (\Exception $e) { } catch (\Exception $e) {
Util::writeLog( \OC::$server->getLogger()->logException($e, [
'federatedfilesharing', 'message' => 'Invalid remote storage.',
'Invalid remote storage: ' . get_class($e) . ': ' . $e->getMessage(), 'level' => \OCP\Util::DEBUG,
Util::DEBUG 'app' => 'federatedfilesharing'
); ]);
$externalManager->removeShare($mount->getMountPoint()); $externalManager->removeShare($mount->getMountPoint());
return new JSONResponse(['message' => $this->l->t('Storage not valid')], Http::STATUS_BAD_REQUEST); return new JSONResponse(['message' => $this->l->t('Storage not valid')], Http::STATUS_BAD_REQUEST);
} }
@ -312,18 +316,18 @@ class MountPublicLinkController extends Controller {
] ]
); );
} catch (StorageInvalidException $e) { } catch (StorageInvalidException $e) {
Util::writeLog( \OC::$server->getLogger()->logException($e, [
'federatedfilesharing', 'message' => 'Invalid remote storage.',
'Invalid remote storage: ' . get_class($e) . ': ' . $e->getMessage(), 'level' => \OCP\Util::DEBUG,
Util::DEBUG 'app' => 'federatedfilesharing'
); ]);
return new JSONResponse(['message' => $this->l->t('Storage not valid')], Http::STATUS_BAD_REQUEST); return new JSONResponse(['message' => $this->l->t('Storage not valid')], Http::STATUS_BAD_REQUEST);
} catch (\Exception $e) { } catch (\Exception $e) {
Util::writeLog( \OC::$server->getLogger()->logException($e, [
'federatedfilesharing', 'message' => 'Invalid remote storage.',
'Invalid remote storage: ' . get_class($e) . ': ' . $e->getMessage(), 'level' => \OCP\Util::DEBUG,
Util::DEBUG 'app' => 'federatedfilesharing'
); ]);
return new JSONResponse(['message' => $this->l->t('Couldn\'t add remote share')], Http::STATUS_BAD_REQUEST); return new JSONResponse(['message' => $this->l->t('Couldn\'t add remote share')], Http::STATUS_BAD_REQUEST);
} }
} else { } else {

View File

@ -209,7 +209,11 @@ class RequestHandlerController extends OCSController {
return new Http\DataResponse(); return new Http\DataResponse();
} catch (\Exception $e) { } catch (\Exception $e) {
\OCP\Util::writeLog('files_sharing', 'server can not add remote share, ' . $e->getMessage(), \OCP\Util::ERROR); \OC::$server->getLogger()->logException($e, [
'message' => 'Server can not add remote share.',
'level' => \OCP\Util::ERROR,
'app' => 'files_sharing'
]);
throw new OCSException('internal server error, was not able to add share from ' . $remote, 500); throw new OCSException('internal server error, was not able to add share from ' . $remote, 500);
} }
} }

View File

@ -264,7 +264,11 @@ class FederatedShareProvider implements IShareProvider {
$failure = true; $failure = true;
} }
} catch (\Exception $e) { } catch (\Exception $e) {
$this->logger->error('Failed to notify remote server of federated share, removing share (' . $e->getMessage() . ')'); $this->logger->logException($e, [
'message' => 'Failed to notify remote server of federated share, removing share.',
'level' => \OCP\Util::ERROR,
'app' => 'federatedfilesharing',
]);
$failure = true; $failure = true;
} }

View File

@ -201,10 +201,18 @@ class GetSharedSecret extends Job {
} }
} catch (RequestException $e) { } catch (RequestException $e) {
$status = -1; // There is no status code if we could not connect $status = -1; // There is no status code if we could not connect
$this->logger->info('Could not connect to ' . $target, ['app' => 'federation']); $this->logger->logException($e, [
'message' => 'Could not connect to ' . $target,
'level' => \OCP\Util::INFO,
'app' => 'federation',
]);
} catch (RingException $e) { } catch (RingException $e) {
$status = -1; // There is no status code if we could not connect $status = -1; // There is no status code if we could not connect
$this->logger->info('Could not connect to ' . $target, ['app' => 'federation']); $this->logger->logException($e, [
'message' => 'Could not connect to ' . $target,
'level' => \OCP\Util::INFO,
'app' => 'federation',
]);
} catch (\Exception $e) { } catch (\Exception $e) {
$status = Http::STATUS_INTERNAL_SERVER_ERROR; $status = Http::STATUS_INTERNAL_SERVER_ERROR;
$this->logger->logException($e, ['app' => 'federation']); $this->logger->logException($e, ['app' => 'federation']);

View File

@ -71,7 +71,10 @@ class AddServerMiddleware extends Middleware {
if (($controller instanceof SettingsController) === false) { if (($controller instanceof SettingsController) === false) {
throw $exception; throw $exception;
} }
$this->logger->error($exception->getMessage(), ['app' => $this->appName]); $this->logger->logException($exception, [
'level' => \OCP\Util::ERROR,
'app' => $this->appName,
]);
if ($exception instanceof HintException) { if ($exception instanceof HintException) {
$message = $exception->getHint(); $message = $exception->getHint();
} else { } else {

View File

@ -49,7 +49,11 @@ class SyncJob extends TimedJob {
protected function run($argument) { protected function run($argument) {
$this->syncService->syncThemAll(function($url, $ex) { $this->syncService->syncThemAll(function($url, $ex) {
if ($ex instanceof \Exception) { if ($ex instanceof \Exception) {
$this->logger->error("Error while syncing $url : " . $ex->getMessage(), ['app' => 'fed-sync']); $this->logger->logException($ex, [
'message' => "Error while syncing $url.",
'level' => \OCP\Util::ERROR,
'app' => 'fed-sync',
]);
} }
}); });
} }

View File

@ -241,7 +241,11 @@ class TrustedServers {
} }
} catch (\Exception $e) { } catch (\Exception $e) {
$this->logger->debug('No Nextcloud server: ' . $e->getMessage()); \OC::$server->getLogger()->logException($e, [
'message' => 'No Nextcloud server.',
'level' => \OCP\Util::DEBUG,
'app' => 'federation',
]);
return false; return false;
} }

View File

@ -68,13 +68,11 @@ class AddServerMiddlewareTest extends TestCase {
* @dataProvider dataTestAfterException * @dataProvider dataTestAfterException
* *
* @param \Exception $exception * @param \Exception $exception
* @param string $message
* @param string $hint * @param string $hint
*/ */
public function testAfterException($exception, $message, $hint) { public function testAfterException($exception, $hint) {
$this->logger->expects($this->once())->method('error') $this->logger->expects($this->once())->method('logException');
->with($message, ['app' => 'AddServerMiddlewareTest']);
$this->l10n->expects($this->any())->method('t') $this->l10n->expects($this->any())->method('t')
->willReturnCallback( ->willReturnCallback(
@ -98,8 +96,8 @@ class AddServerMiddlewareTest extends TestCase {
public function dataTestAfterException() { public function dataTestAfterException() {
return [ return [
[new HintException('message', 'hint'), 'message', 'hint'], [new HintException('message', 'hint'), 'hint'],
[new \Exception('message'), 'message', 'message'], [new \Exception('message'), 'message'],
]; ];
} }

View File

@ -138,7 +138,10 @@ class Swift extends \OC\Files\Storage\Common {
} catch (ClientErrorResponseException $e) { } catch (ClientErrorResponseException $e) {
// Expected response is "404 Not Found", so only log if it isn't // Expected response is "404 Not Found", so only log if it isn't
if ($e->getResponse()->getStatusCode() !== 404) { if ($e->getResponse()->getStatusCode() !== 404) {
\OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR); \OC::$server->getLogger()->logException($e, [
'level' => \OCP\Util::ERROR,
'app' => 'files_external',
]);
} }
return false; return false;
} }
@ -206,7 +209,10 @@ class Swift extends \OC\Files\Storage\Common {
// with all properties // with all properties
$this->objectCache->remove($path); $this->objectCache->remove($path);
} catch (Exceptions\CreateUpdateError $e) { } catch (Exceptions\CreateUpdateError $e) {
\OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR); \OC::$server->getLogger()->logException($e, [
'level' => \OCP\Util::ERROR,
'app' => 'files_external',
]);
return false; return false;
} }
@ -247,7 +253,10 @@ class Swift extends \OC\Files\Storage\Common {
$this->getContainer()->dataObject()->setName($path . '/')->delete(); $this->getContainer()->dataObject()->setName($path . '/')->delete();
$this->objectCache->remove($path . '/'); $this->objectCache->remove($path . '/');
} catch (Exceptions\DeleteError $e) { } catch (Exceptions\DeleteError $e) {
\OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR); \OC::$server->getLogger()->logException($e, [
'level' => \OCP\Util::ERROR,
'app' => 'files_external',
]);
return false; return false;
} }
@ -283,7 +292,10 @@ class Swift extends \OC\Files\Storage\Common {
return IteratorDirectory::wrap($files); return IteratorDirectory::wrap($files);
} catch (\Exception $e) { } catch (\Exception $e) {
\OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR); \OC::$server->getLogger()->logException($e, [
'level' => \OCP\Util::ERROR,
'app' => 'files_external',
]);
return false; return false;
} }
@ -305,7 +317,10 @@ class Swift extends \OC\Files\Storage\Common {
return false; return false;
} }
} catch (ClientErrorResponseException $e) { } catch (ClientErrorResponseException $e) {
\OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR); \OC::$server->getLogger()->logException($e, [
'level' => \OCP\Util::ERROR,
'app' => 'files_external',
]);
return false; return false;
} }
@ -361,7 +376,10 @@ class Swift extends \OC\Files\Storage\Common {
$this->objectCache->remove($path . '/'); $this->objectCache->remove($path . '/');
} catch (ClientErrorResponseException $e) { } catch (ClientErrorResponseException $e) {
if ($e->getResponse()->getStatusCode() !== 404) { if ($e->getResponse()->getStatusCode() !== 404) {
\OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR); \OC::$server->getLogger()->logException($e, [
'level' => \OCP\Util::ERROR,
'app' => 'files_external',
]);
} }
return false; return false;
} }
@ -394,7 +412,10 @@ class Swift extends \OC\Files\Storage\Common {
} }
return false; return false;
} catch (\Guzzle\Http\Exception\BadResponseException $e) { } catch (\Guzzle\Http\Exception\BadResponseException $e) {
\OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR); \OC::$server->getLogger()->logException($e, [
'level' => \OCP\Util::ERROR,
'app' => 'files_external',
]);
return false; return false;
} }
case 'w': case 'w':
@ -474,7 +495,10 @@ class Swift extends \OC\Files\Storage\Common {
$this->objectCache->remove($path2); $this->objectCache->remove($path2);
$this->objectCache->remove($path2 . '/'); $this->objectCache->remove($path2 . '/');
} catch (ClientErrorResponseException $e) { } catch (ClientErrorResponseException $e) {
\OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR); \OC::$server->getLogger()->logException($e, [
'level' => \OCP\Util::ERROR,
'app' => 'files_external',
]);
return false; return false;
} }
@ -490,7 +514,10 @@ class Swift extends \OC\Files\Storage\Common {
$this->objectCache->remove($path2); $this->objectCache->remove($path2);
$this->objectCache->remove($path2 . '/'); $this->objectCache->remove($path2 . '/');
} catch (ClientErrorResponseException $e) { } catch (ClientErrorResponseException $e) {
\OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR); \OC::$server->getLogger()->logException($e, [
'level' => \OCP\Util::ERROR,
'app' => 'files_external',
]);
return false; return false;
} }

View File

@ -192,11 +192,11 @@ abstract class LegacyStoragesService {
} }
} catch (\UnexpectedValueException $e) { } catch (\UnexpectedValueException $e) {
// don't die if a storage backend doesn't exist // don't die if a storage backend doesn't exist
\OCP\Util::writeLog( \OC::$server->getLogger()->logException($e, [
'files_external', 'message' => 'Could not load storage.',
'Could not load storage: "' . $e->getMessage() . '"', 'level' => \OCP\Util::ERROR,
\OCP\Util::ERROR 'app' => 'files_external',
); ]);
} }
} }
} }

View File

@ -102,18 +102,18 @@ abstract class StoragesService {
return $config; return $config;
} catch (\UnexpectedValueException $e) { } catch (\UnexpectedValueException $e) {
// don't die if a storage backend doesn't exist // don't die if a storage backend doesn't exist
\OCP\Util::writeLog( \OC::$server->getLogger()->logException($e, [
'files_external', 'message' => 'Could not load storage.',
'Could not load storage: "' . $e->getMessage() . '"', 'level' => \OCP\Util::ERROR,
\OCP\Util::ERROR 'app' => 'files_external',
); ]);
return null; return null;
} catch (\InvalidArgumentException $e) { } catch (\InvalidArgumentException $e) {
\OCP\Util::writeLog( \OC::$server->getLogger()->logException($e, [
'files_external', 'message' => 'Could not load storage.',
'Could not load storage: "' . $e->getMessage() . '"', 'level' => \OCP\Util::ERROR,
\OCP\Util::ERROR 'app' => 'files_external',
); ]);
return null; return null;
} }
} }
@ -478,11 +478,10 @@ abstract class StoragesService {
// can happen either for invalid configs where the storage could not // can happen either for invalid configs where the storage could not
// be instantiated or whenever $user vars where used, in which case // be instantiated or whenever $user vars where used, in which case
// the storage id could not be computed // the storage id could not be computed
\OCP\Util::writeLog( \OC::$server->getLogger()->logException($e, [
'files_external', 'level' => \OCP\Util::ERROR,
'Exception: "' . $e->getMessage() . '"', 'app' => 'files_external',
\OCP\Util::ERROR ]);
);
} }
} }

View File

@ -482,7 +482,7 @@ class ShareAPIController extends OCSController {
$code = $e->getCode() === 0 ? 403 : $e->getCode(); $code = $e->getCode() === 0 ? 403 : $e->getCode();
throw new OCSException($e->getHint(), $code); throw new OCSException($e->getHint(), $code);
} catch (\Exception $e) { } catch (\Exception $e) {
throw new OCSForbiddenException($e->getMessage()); throw new OCSForbiddenException($e->getMessage(), $e);
} }
$output = $this->formatShare($share); $output = $this->formatShare($share);
@ -749,7 +749,7 @@ class ShareAPIController extends OCSController {
try { try {
$expireDate = $this->parseDate($expireDate); $expireDate = $this->parseDate($expireDate);
} catch (\Exception $e) { } catch (\Exception $e) {
throw new OCSBadRequestException($e->getMessage()); throw new OCSBadRequestException($e->getMessage(), $e);
} }
$share->setExpirationDate($expireDate); $share->setExpirationDate($expireDate);
} }
@ -780,7 +780,7 @@ class ShareAPIController extends OCSController {
try { try {
$expireDate = $this->parseDate($expireDate); $expireDate = $this->parseDate($expireDate);
} catch (\Exception $e) { } catch (\Exception $e) {
throw new OCSBadRequestException($e->getMessage()); throw new OCSBadRequestException($e->getMessage(), $e);
} }
$share->setExpirationDate($expireDate); $share->setExpirationDate($expireDate);
} }
@ -809,7 +809,7 @@ class ShareAPIController extends OCSController {
try { try {
$share = $this->shareManager->updateShare($share); $share = $this->shareManager->updateShare($share);
} catch (\Exception $e) { } catch (\Exception $e) {
throw new OCSBadRequestException($e->getMessage()); throw new OCSBadRequestException($e->getMessage(), $e);
} }
return new DataResponse($this->formatShare($share)); return new DataResponse($this->formatShare($share));

View File

@ -130,8 +130,11 @@ class Storage extends Wrapper {
} }
} catch (\Exception $e) { } catch (\Exception $e) {
// do nothing, in this case we just disable the trashbin and continue // do nothing, in this case we just disable the trashbin and continue
$logger = \OC::$server->getLogger(); \OC::$server->getLogger()->logException($e, [
$logger->debug('Trashbin storage could not check if a file was moved out of a shared folder: ' . $e->getMessage()); 'message' => 'Trashbin storage could not check if a file was moved out of a shared folder.',
'level' => \OCP\Util::DEBUG,
'app' => 'files_trashbin',
]);
} }
if($fileMovedOutOfSharedFolder) { if($fileMovedOutOfSharedFolder) {

View File

@ -197,7 +197,11 @@ class UsersController extends OCSController {
} }
return new DataResponse(); return new DataResponse();
} catch (\Exception $e) { } catch (\Exception $e) {
$this->logger->error('Failed addUser attempt with exception: '.$e->getMessage(), ['app' => 'ocs_api']); $this->logger->logException($e, [
'message' => 'Failed addUser attempt with exception.',
'level' => \OCP\Util::ERROR,
'app' => 'ocs_api',
]);
throw new OCSException('Bad request', 101); throw new OCSException('Bad request', 101);
} }
} }
@ -826,7 +830,11 @@ class UsersController extends OCSController {
$emailTemplate = $this->newUserMailHelper->generateTemplate($targetUser, false); $emailTemplate = $this->newUserMailHelper->generateTemplate($targetUser, false);
$this->newUserMailHelper->sendMail($targetUser, $emailTemplate); $this->newUserMailHelper->sendMail($targetUser, $emailTemplate);
} catch(\Exception $e) { } catch(\Exception $e) {
$this->logger->error("Can't send new user mail to $email: " . $e->getMessage(), array('app' => 'settings')); $this->logger->logException($e, [
'message' => "Can't send new user mail to $email",
'level' => \OCP\Util::ERROR,
'app' => 'settings',
]);
throw new OCSException('Sending email failed', 102); throw new OCSException('Sending email failed', 102);
} }

View File

@ -414,6 +414,7 @@ class UsersControllerTest extends TestCase {
* @expectedExceptionMessage Bad request * @expectedExceptionMessage Bad request
*/ */
public function testAddUserUnsuccessful() { public function testAddUserUnsuccessful() {
$exception = new Exception('User backend not found.');
$this->userManager $this->userManager
->expects($this->once()) ->expects($this->once())
->method('userExists') ->method('userExists')
@ -423,11 +424,15 @@ class UsersControllerTest extends TestCase {
->expects($this->once()) ->expects($this->once())
->method('createUser') ->method('createUser')
->with('NewUser', 'PasswordOfTheNewUser') ->with('NewUser', 'PasswordOfTheNewUser')
->will($this->throwException(new Exception('User backend not found.'))); ->will($this->throwException($exception));
$this->logger $this->logger
->expects($this->once()) ->expects($this->once())
->method('error') ->method('logException')
->with('Failed addUser attempt with exception: User backend not found.', ['app' => 'ocs_api']); ->with($exception, [
'message' => 'Failed addUser attempt with exception.',
'level' => \OCP\Util::ERROR,
'app' => 'ocs_api',
]);
$loggedInUser = $this->getMockBuilder(IUser::class) $loggedInUser = $this->getMockBuilder(IUser::class)
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();

View File

@ -351,11 +351,19 @@ class ShareByMailProvider implements IShareProvider {
$share->getExpirationDate() $share->getExpirationDate()
); );
} catch (HintException $hintException) { } catch (HintException $hintException) {
$this->logger->error('Failed to send share by mail: ' . $hintException->getMessage()); $this->logger->logException($hintException, [
'message' => 'Failed to send share by mail.',
'level' => \OCP\Util::ERROR,
'app' => 'sharebymail',
]);
$this->removeShareFromTable($shareId); $this->removeShareFromTable($shareId);
throw $hintException; throw $hintException;
} catch (\Exception $e) { } catch (\Exception $e) {
$this->logger->error('Failed to send share by email: ' . $e->getMessage()); $this->logger->logException($e, [
'message' => 'Failed to send share by mail.',
'level' => \OCP\Util::ERROR,
'app' => 'sharebymail',
]);
$this->removeShareFromTable($shareId); $this->removeShareFromTable($shareId);
throw new HintException('Failed to send share by mail', throw new HintException('Failed to send share by mail',
$this->l->t('Failed to send share by email')); $this->l->t('Failed to send share by email'));

View File

@ -595,9 +595,11 @@ class User {
$avatar = $this->avatarManager->getAvatar($this->uid); $avatar = $this->avatarManager->getAvatar($this->uid);
$avatar->set($this->image); $avatar->set($this->image);
} catch (\Exception $e) { } catch (\Exception $e) {
\OC::$server->getLogger()->notice( \OC::$server->getLogger()->logException($e, [
'Could not set avatar for ' . $this->dn . ', because: ' . $e->getMessage(), 'message' => 'Could not set avatar for ' . $this->dn,
['app' => 'user_ldap']); 'level' => \OCP\Util::INFO,
'app' => 'user_ldap',
]);
} }
} }

View File

@ -207,6 +207,10 @@ if (\OCP\Util::needUpgrade()) {
try { try {
$updater->upgrade(); $updater->upgrade();
} catch (\Exception $e) { } catch (\Exception $e) {
\OC::$server->getLogger()->logException($e, [
'level' => \OCP\Util::ERROR,
'app' => 'update',
]);
$eventSource->send('failure', get_class($e) . ': ' . $e->getMessage()); $eventSource->send('failure', get_class($e) . ': ' . $e->getMessage());
$eventSource->close(); $eventSource->close();
exit(); exit();

View File

@ -809,7 +809,11 @@ class OC {
} catch (\Exception $e) { } catch (\Exception $e) {
// a GC exception should not prevent users from using OC, // a GC exception should not prevent users from using OC,
// so log the exception // 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',
]);
} }
}); });
} }

View File

@ -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; return $response;
} }

View File

@ -55,7 +55,11 @@ class CapabilitiesManager {
try { try {
$c = $capability(); $c = $capability();
} catch (QueryException $e) { } 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; continue;
} }

View File

@ -452,7 +452,11 @@ class Scanner extends BasicEmitter implements IScanner {
\OC::$server->getDatabaseConnection()->rollback(); \OC::$server->getDatabaseConnection()->rollback();
\OC::$server->getDatabaseConnection()->beginTransaction(); \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; $exceptionOccurred = true;
} catch (\OCP\Lock\LockedException $e) { } catch (\OCP\Lock\LockedException $e) {
if ($this->useTransactions) { if ($this->useTransactions) {

View File

@ -109,7 +109,11 @@ trait S3ConnectionTrait {
)); ));
$this->testTimeout(); $this->testTimeout();
} catch (S3Exception $e) { } 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()); throw new \Exception('Creation of bucket failed. ' . $e->getMessage());
} }
} }

View File

@ -830,8 +830,7 @@ class DAV extends Common {
* which might be temporary * which might be temporary
*/ */
protected function convertException(Exception $e, $path = '') { protected function convertException(Exception $e, $path = '') {
\OC::$server->getLogger()->logException($e); \OC::$server->getLogger()->logException($e, ['app' => 'files_external']);
Util::writeLog('files_external', $e->getMessage(), Util::ERROR);
if ($e instanceof ClientHttpException) { if ($e instanceof ClientHttpException) {
if ($e->getHttpStatus() === Http::STATUS_LOCKED) { if ($e->getHttpStatus() === Http::STATUS_LOCKED) {
throw new \OCP\Lock\LockedException($path); throw new \OCP\Lock\LockedException($path);

View File

@ -441,8 +441,11 @@ class Encryption extends Wrapper {
} }
} }
} catch (ModuleDoesNotExistsException $e) { } catch (ModuleDoesNotExistsException $e) {
$this->logger->warning('Encryption module "' . $encryptionModuleId . $this->logger->logException($e, [
'" not found, file will be stored unencrypted (' . $e->getMessage() . ')'); '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 // encryption disabled on write of new file and write to existing unencrypted file -> don't encrypt

View File

@ -1464,12 +1464,11 @@ class View {
continue; continue;
} catch (\Exception $e) { } catch (\Exception $e) {
// sometimes when the storage is not available it can be any exception // sometimes when the storage is not available it can be any exception
\OCP\Util::writeLog( \OC::$server->getLogger()->logException($e, [
'core', 'message' => 'Exception while scanning storage "' . $subStorage->getId() . '"',
'Exception while scanning storage "' . $subStorage->getId() . '": ' . 'level' => \OCP\Util::ERROR,
get_class($e) . ': ' . $e->getMessage(), 'app' => 'lib',
\OCP\Util::ERROR ]);
);
continue; continue;
} }
$rootEntry = $subCache->get(''); $rootEntry = $subCache->get('');

View File

@ -195,7 +195,10 @@ class Installer {
try { try {
$this->downloadApp($appId); $this->downloadApp($appId);
} catch (\Exception $e) { } catch (\Exception $e) {
$this->logger->error($e->getMessage(), ['app' => 'core']); $this->logger->logException($e, [
'level' => \OCP\Util::ERROR,
'app' => 'core',
]);
return false; return false;
} }
return OC_App::updateApp($appId); return OC_App::updateApp($appId);

View File

@ -48,7 +48,11 @@ abstract class Bitmap extends Provider {
try { try {
$bp = $this->getResizedPreview($tmpPath, $maxX, $maxY); $bp = $this->getResizedPreview($tmpPath, $maxX, $maxY);
} catch (\Exception $e) { } 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; return false;
} }

View File

@ -59,7 +59,10 @@ abstract class Office extends Provider {
} catch (\Exception $e) { } catch (\Exception $e) {
unlink($absPath); unlink($absPath);
unlink($pdfPreview); unlink($pdfPreview);
\OCP\Util::writeLog('core', $e->getMessage(), \OCP\Util::ERROR); \OC::$server->getLogger()->logException($e, [
'level' => \OCP\Util::ERROR,
'app' => 'core',
]);
return false; return false;
} }

View File

@ -53,7 +53,10 @@ class SVG extends Provider {
$svg->readImageBlob($content); $svg->readImageBlob($content);
$svg->setImageFormat('png32'); $svg->setImageFormat('png32');
} catch (\Exception $e) { } 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; return false;
} }

View File

@ -68,9 +68,10 @@ class MySQL extends AbstractDatabase {
$query = "CREATE DATABASE IF NOT EXISTS `$name` CHARACTER SET $characterSet COLLATE ${characterSet}_bin;"; $query = "CREATE DATABASE IF NOT EXISTS `$name` CHARACTER SET $characterSet COLLATE ${characterSet}_bin;";
$connection->executeUpdate($query); $connection->executeUpdate($query);
} catch (\Exception $ex) { } 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', 'app' => 'mysql.setup',
'error' => $ex->getMessage()
]); ]);
return; return;
} }
@ -80,9 +81,10 @@ class MySQL extends AbstractDatabase {
$query="GRANT ALL PRIVILEGES ON `$name` . * TO '$user'"; $query="GRANT ALL PRIVILEGES ON `$name` . * TO '$user'";
$connection->executeUpdate($query); $connection->executeUpdate($query);
} catch (\Exception $ex) { } 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', 'app' => 'mysql.setup',
'error' => $ex->getMessage()
]); ]);
} }
} }
@ -103,10 +105,11 @@ class MySQL extends AbstractDatabase {
$connection->executeUpdate($query); $connection->executeUpdate($query);
} }
catch (\Exception $ex){ catch (\Exception $ex){
$this->logger->error('Database User creation failed: {error}', [ $this->logger->logException($ex, [
'app' => 'mysql.setup', 'message' => 'Database user creation failed.',
'error' => $ex->getMessage() 'level' => \OCP\Util::ERROR,
]); 'app' => 'mysql.setup',
]);
} }
} }
@ -157,9 +160,10 @@ class MySQL extends AbstractDatabase {
}; };
} }
} catch (\Exception $ex) { } 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', 'app' => 'mysql.setup',
'error' => $ex->getMessage()
]); ]);
} }

View File

@ -242,8 +242,11 @@ class Tags implements \OCP\ITags {
} }
} }
} catch(\Exception $e) { } catch(\Exception $e) {
\OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(), \OC::$server->getLogger()->logException($e, [
\OCP\Util::ERROR); 'message' => __METHOD__,
'level' => \OCP\Util::ERROR,
'app' => 'core',
]);
return false; return false;
} }
@ -292,8 +295,11 @@ class Tags implements \OCP\ITags {
return false; return false;
} }
} catch(\Exception $e) { } catch(\Exception $e) {
\OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(), \OC::$server->getLogger()->logException($e, [
\OCP\Util::ERROR); 'message' => __METHOD__,
'level' => \OCP\Util::ERROR,
'app' => 'core',
]);
return false; return false;
} }
@ -366,8 +372,11 @@ class Tags implements \OCP\ITags {
$tag = $this->mapper->insert($tag); $tag = $this->mapper->insert($tag);
$this->tags[] = $tag; $this->tags[] = $tag;
} catch(\Exception $e) { } catch(\Exception $e) {
\OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(), \OC::$server->getLogger()->logException($e, [
\OCP\Util::ERROR); 'message' => __METHOD__,
'level' => \OCP\Util::ERROR,
'app' => 'core',
]);
return false; return false;
} }
\OCP\Util::writeLog('core', __METHOD__.', id: ' . $tag->getId(), \OCP\Util::DEBUG); \OCP\Util::writeLog('core', __METHOD__.', id: ' . $tag->getId(), \OCP\Util::DEBUG);
@ -410,8 +419,11 @@ class Tags implements \OCP\ITags {
$tag->setName($to); $tag->setName($to);
$this->tags[$key] = $this->mapper->update($tag); $this->tags[$key] = $this->mapper->update($tag);
} catch(\Exception $e) { } catch(\Exception $e) {
\OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(), \OC::$server->getLogger()->logException($e, [
\OCP\Util::ERROR); 'message' => __METHOD__,
'level' => \OCP\Util::ERROR,
'app' => 'core',
]);
return false; return false;
} }
return true; return true;
@ -462,8 +474,11 @@ class Tags implements \OCP\ITags {
$this->mapper->insert($tag); $this->mapper->insert($tag);
} }
} catch(\Exception $e) { } catch(\Exception $e) {
\OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(), \OC::$server->getLogger()->logException($e, [
\OCP\Util::ERROR); 'message' => __METHOD__,
'level' => \OCP\Util::ERROR,
'app' => 'core',
]);
} }
} }
@ -488,8 +503,11 @@ class Tags implements \OCP\ITags {
'type' => $this->type, 'type' => $this->type,
)); ));
} catch(\Exception $e) { } catch(\Exception $e) {
\OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(), \OC::$server->getLogger()->logException($e, [
\OCP\Util::ERROR); '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); \OCP\Util::writeLog('core', __METHOD__. 'DB error: ' . \OCP\DB::getErrorMessage(), \OCP\Util::ERROR);
} }
} catch(\Exception $e) { } catch(\Exception $e) {
\OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(), \OC::$server->getLogger()->logException($e, [
\OCP\Util::ERROR); 'message' => __METHOD__,
'level' => \OCP\Util::ERROR,
'app' => 'core',
]);
} }
if(!is_null($result)) { if(!is_null($result)) {
@ -530,13 +551,19 @@ class Tags implements \OCP\ITags {
try { try {
$stmt->execute(array($row['id'])); $stmt->execute(array($row['id']));
} catch(\Exception $e) { } catch(\Exception $e) {
\OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(), \OC::$server->getLogger()->logException($e, [
\OCP\Util::ERROR); 'message' => __METHOD__,
'level' => \OCP\Util::ERROR,
'app' => 'core',
]);
} }
} }
} catch(\Exception $e) { } catch(\Exception $e) {
\OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(), \OC::$server->getLogger()->logException($e, [
\OCP\Util::ERROR); 'message' => __METHOD__,
'level' => \OCP\Util::ERROR,
'app' => 'core',
]);
} }
} }
try { try {
@ -547,8 +574,11 @@ class Tags implements \OCP\ITags {
\OCP\Util::writeLog('core', __METHOD__. ', DB error: ' . \OCP\DB::getErrorMessage(), \OCP\Util::ERROR); \OCP\Util::writeLog('core', __METHOD__. ', DB error: ' . \OCP\DB::getErrorMessage(), \OCP\Util::ERROR);
} }
} catch(\Exception $e) { } catch(\Exception $e) {
\OCP\Util::writeLog('core', __METHOD__ . ', exception: ' \OC::$server->getLogger()->logException($e, [
. $e->getMessage(), \OCP\Util::ERROR); 'message' => __METHOD__,
'level' => \OCP\Util::ERROR,
'app' => 'core',
]);
} }
} }
@ -576,8 +606,11 @@ class Tags implements \OCP\ITags {
return false; return false;
} }
} catch(\Exception $e) { } catch(\Exception $e) {
\OCP\Util::writeLog('core', __METHOD__.', exception: ' . $e->getMessage(), \OC::$server->getLogger()->logException($e, [
\OCP\Util::ERROR); 'message' => __METHOD__,
'level' => \OCP\Util::ERROR,
'app' => 'core',
]);
return false; return false;
} }
return true; return true;
@ -592,8 +625,11 @@ class Tags implements \OCP\ITags {
try { try {
return $this->getIdsForTag(self::TAG_FAVORITE); return $this->getIdsForTag(self::TAG_FAVORITE);
} catch(\Exception $e) { } catch(\Exception $e) {
\OCP\Util::writeLog('core', __METHOD__.', exception: ' . $e->getMessage(), \OC::$server->getLogger()->logException($e, [
\OCP\Util::DEBUG); 'message' => __METHOD__,
'level' => \OCP\Util::ERROR,
'app' => 'core',
]);
return array(); return array();
} }
} }
@ -650,8 +686,11 @@ class Tags implements \OCP\ITags {
'type' => $this->type, 'type' => $this->type,
)); ));
} catch(\Exception $e) { } catch(\Exception $e) {
\OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(), \OC::$server->getLogger()->logException($e, [
\OCP\Util::ERROR); 'message' => __METHOD__,
'level' => \OCP\Util::ERROR,
'app' => 'core',
]);
return false; return false;
} }
return true; return true;
@ -682,8 +721,11 @@ class Tags implements \OCP\ITags {
$stmt = \OCP\DB::prepare($sql); $stmt = \OCP\DB::prepare($sql);
$stmt->execute(array($objid, $tagId, $this->type)); $stmt->execute(array($objid, $tagId, $this->type));
} catch(\Exception $e) { } catch(\Exception $e) {
\OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(), \OC::$server->getLogger()->logException($e, [
\OCP\Util::ERROR); 'message' => __METHOD__,
'level' => \OCP\Util::ERROR,
'app' => 'core',
]);
return false; return false;
} }
return true; return true;
@ -735,8 +777,11 @@ class Tags implements \OCP\ITags {
return false; return false;
} }
} catch(\Exception $e) { } catch(\Exception $e) {
\OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(), \OC::$server->getLogger()->logException($e, [
\OCP\Util::ERROR); 'message' => __METHOD__,
'level' => \OCP\Util::ERROR,
'app' => 'core',
]);
return false; return false;
} }
} }

View File

@ -487,7 +487,11 @@ class UsersController extends Controller {
$emailTemplate = $this->newUserMailHelper->generateTemplate($user, $generatePasswordResetToken); $emailTemplate = $this->newUserMailHelper->generateTemplate($user, $generatePasswordResetToken);
$this->newUserMailHelper->sendMail($user, $emailTemplate); $this->newUserMailHelper->sendMail($user, $emailTemplate);
} catch (\Exception $e) { } catch (\Exception $e) {
$this->log->error("Can't send new user mail to $email: " . $e->getMessage(), ['app' => 'settings']); $this->log->logException($e, [
'message' => "Can't send new user mail to $email",
'level' => \OCP\Util::ERROR,
'app' => 'settings',
]);
} }
} }
// fetch users groups // fetch users groups

View File

@ -50,6 +50,9 @@ try {
OC_JSON::success(['data' => ['update_required' => $updateRequired]]); OC_JSON::success(['data' => ['update_required' => $updateRequired]]);
} catch (Exception $e) { } catch (Exception $e) {
\OCP\Util::writeLog('core', $e->getMessage(), \OCP\Util::ERROR); \OC::$server->getLogger()->logException($e, [
'level' => \OCP\Util::DEBUG,
'app' => 'core',
]);
OC_JSON::error(array("data" => array("message" => $e->getMessage()) )); OC_JSON::error(array("data" => array("message" => $e->getMessage()) ));
} }

View File

@ -483,8 +483,7 @@ class SecurityMiddlewareTest extends \Test\TestCase {
->will($this->returnValue('http://localhost/nextcloud/index.php/login?redirect_url=nextcloud/index.php/apps/specialapp')); ->will($this->returnValue('http://localhost/nextcloud/index.php/login?redirect_url=nextcloud/index.php/apps/specialapp'));
$this->logger $this->logger
->expects($this->once()) ->expects($this->once())
->method('debug') ->method('logException');
->with('Current user is not logged in');
$response = $this->middleware->afterException( $response = $this->middleware->afterException(
$this->controller, $this->controller,
'test', 'test',
@ -554,8 +553,7 @@ class SecurityMiddlewareTest extends \Test\TestCase {
$this->middleware = $this->getMiddleware(false, false); $this->middleware = $this->getMiddleware(false, false);
$this->logger $this->logger
->expects($this->once()) ->expects($this->once())
->method('debug') ->method('logException');
->with($exception->getMessage());
$response = $this->middleware->afterException( $response = $this->middleware->afterException(
$this->controller, $this->controller,
'test', 'test',

View File

@ -148,7 +148,7 @@ class CapabilitiesManagerTest extends TestCase {
}); });
$this->logger->expects($this->once()) $this->logger->expects($this->once())
->method('error'); ->method('logException');
$res = $this->manager->getCapabilities(); $res = $this->manager->getCapabilities();