From c0ce272e9c3a94ff98081c4f90a31ca611d28323 Mon Sep 17 00:00:00 2001 From: =?utf8?q?C=C3=B4me=20Chilliet?= Date: Thu, 8 Feb 2024 15:47:39 +0100 Subject: [PATCH] chore: Migrate away from OC::$server->getLogger MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- .../lib/Controller/ShareAPIController.php | 4 +- .../lib/DeleteOrphanedSharesJob.php | 13 +-- apps/files_sharing/lib/ShareBackend/File.php | 3 +- apps/files_sharing/lib/SharedMount.php | 11 ++- apps/user_ldap/lib/Configuration.php | 4 +- apps/user_ldap/lib/GroupPluginManager.php | 3 +- .../user_ldap/lib/Mapping/AbstractMapping.php | 3 +- apps/user_ldap/lib/UserPluginManager.php | 5 +- .../Integration/AbstractIntegrationTest.php | 2 +- lib/private/Cache/File.php | 8 +- lib/private/Files/Filesystem.php | 3 +- .../Files/ObjectStore/ObjectStoreStorage.php | 87 ++++++++++++------- lib/private/L10N/L10N.php | 3 +- lib/private/Log/Rotate.php | 12 +-- lib/private/Search.php | 3 +- lib/private/Share20/DefaultShareProvider.php | 4 +- lib/private/Tags.php | 15 ++-- lib/private/User/Manager.php | 3 +- lib/public/AppFramework/App.php | 4 +- ocs/v1.php | 3 +- public.php | 6 +- status.php | 4 +- 22 files changed, 127 insertions(+), 76 deletions(-) diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php index aa239ae8bb6..26a868381e6 100644 --- a/apps/files_sharing/lib/Controller/ShareAPIController.php +++ b/apps/files_sharing/lib/Controller/ShareAPIController.php @@ -850,11 +850,11 @@ class ShareAPIController extends OCSController { try { $share = $this->shareManager->createShare($share); } catch (GenericShareException $e) { - \OC::$server->getLogger()->logException($e); + \OCP\Server::get(LoggerInterface::class)->error($e->getMessage(), ['exception' => $e]); $code = $e->getCode() === 0 ? 403 : $e->getCode(); throw new OCSException($e->getHint(), $code); } catch (\Exception $e) { - \OC::$server->getLogger()->logException($e); + \OCP\Server::get(LoggerInterface::class)->error($e->getMessage(), ['exception' => $e]); throw new OCSForbiddenException($e->getMessage(), $e); } diff --git a/apps/files_sharing/lib/DeleteOrphanedSharesJob.php b/apps/files_sharing/lib/DeleteOrphanedSharesJob.php index d2cc39ff060..2d166da2010 100644 --- a/apps/files_sharing/lib/DeleteOrphanedSharesJob.php +++ b/apps/files_sharing/lib/DeleteOrphanedSharesJob.php @@ -26,6 +26,9 @@ namespace OCA\Files_Sharing; use OCP\AppFramework\Utility\ITimeFactory; use OCP\BackgroundJob\TimedJob; +use OCP\IDBConnection; +use OCP\Server; +use Psr\Log\LoggerInterface; /** * Delete all share entries that have no matching entries in the file cache table. @@ -33,10 +36,8 @@ use OCP\BackgroundJob\TimedJob; class DeleteOrphanedSharesJob extends TimedJob { /** * Default interval in minutes - * - * @var int $defaultIntervalMin **/ - protected $defaultIntervalMin = 15; + protected int $defaultIntervalMin = 15; /** * sets the correct interval for this timed job @@ -53,15 +54,15 @@ class DeleteOrphanedSharesJob extends TimedJob { * @param array $argument unused argument */ public function run($argument) { - $connection = \OC::$server->getDatabaseConnection(); - $logger = \OC::$server->getLogger(); + $connection = Server::get(IDBConnection::class); + $logger = Server::get(LoggerInterface::class); $sql = 'DELETE FROM `*PREFIX*share` ' . 'WHERE `item_type` in (\'file\', \'folder\') ' . 'AND NOT EXISTS (SELECT `fileid` FROM `*PREFIX*filecache` WHERE `file_source` = `fileid`)'; - $deletedEntries = $connection->executeUpdate($sql); + $deletedEntries = $connection->executeStatement($sql); $logger->debug("$deletedEntries orphaned share(s) deleted", ['app' => 'DeleteOrphanedSharesJob']); } } diff --git a/apps/files_sharing/lib/ShareBackend/File.php b/apps/files_sharing/lib/ShareBackend/File.php index c84cbd66c67..23096d64156 100644 --- a/apps/files_sharing/lib/ShareBackend/File.php +++ b/apps/files_sharing/lib/ShareBackend/File.php @@ -35,6 +35,7 @@ namespace OCA\Files_Sharing\ShareBackend; use OCA\FederatedFileSharing\FederatedShareProvider; use OCP\Share\IShare; +use Psr\Log\LoggerInterface; class File implements \OCP\Share_Backend_File_Dependent { public const FORMAT_SHARED_STORAGE = 0; @@ -233,7 +234,7 @@ class File implements \OCP\Share_Backend_File_Dependent { if (isset($fileOwner)) { $source['fileOwner'] = $fileOwner; } else { - \OC::$server->getLogger()->error('No owner found for reshare', ['app' => 'files_sharing']); + \OCP\Server::get(LoggerInterface::class)->error('No owner found for reshare', ['app' => 'files_sharing']); } return $source; diff --git a/apps/files_sharing/lib/SharedMount.php b/apps/files_sharing/lib/SharedMount.php index 7dc24936d6b..66a3b619df0 100644 --- a/apps/files_sharing/lib/SharedMount.php +++ b/apps/files_sharing/lib/SharedMount.php @@ -40,6 +40,7 @@ use OCP\Files\Storage\IStorageFactory; use OCP\ICache; use OCP\IUser; use OCP\Share\Events\VerifyMountPointEvent; +use Psr\Log\LoggerInterface; /** * Shared mount points can be moved by the user @@ -198,7 +199,7 @@ class SharedMount extends MountPoint implements MoveableMount, ISharedMountPoint // it is not a file relative to data/user/files if (count($split) < 3 || $split[1] !== 'files') { - \OC::$server->getLogger()->error('Can not strip userid and "files/" from path: ' . $path, ['app' => 'files_sharing']); + \OCP\Server::get(LoggerInterface::class)->error('Can not strip userid and "files/" from path: ' . $path, ['app' => 'files_sharing']); throw new \OCA\Files_Sharing\Exceptions\BrokenPath('Path does not start with /user/files', 10); } @@ -226,7 +227,13 @@ class SharedMount extends MountPoint implements MoveableMount, ISharedMountPoint $this->setMountPoint($target); $this->storage->setMountPoint($relTargetPath); } catch (\Exception $e) { - \OC::$server->getLogger()->logException($e, ['app' => 'files_sharing', 'message' => 'Could not rename mount point for shared folder "' . $this->getMountPoint() . '" to "' . $target . '"']); + \OCP\Server::get(LoggerInterface::class)->error( + 'Could not rename mount point for shared folder "' . $this->getMountPoint() . '" to "' . $target . '"', + [ + 'app' => 'files_sharing', + 'exception' => $e, + ] + ); } return $result; diff --git a/apps/user_ldap/lib/Configuration.php b/apps/user_ldap/lib/Configuration.php index b009ba3f480..2791324be5b 100644 --- a/apps/user_ldap/lib/Configuration.php +++ b/apps/user_ldap/lib/Configuration.php @@ -35,6 +35,8 @@ */ namespace OCA\User_LDAP; +use Psr\Log\LoggerInterface; + /** * @property int ldapPagingSize holds an integer * @property string ldapUserAvatarRule @@ -598,7 +600,7 @@ class Configuration { return [strtolower($attribute)]; } if ($value !== self::AVATAR_PREFIX_DEFAULT) { - \OC::$server->getLogger()->warning('Invalid config value to ldapUserAvatarRule; falling back to default.'); + \OCP\Server::get(LoggerInterface::class)->warning('Invalid config value to ldapUserAvatarRule; falling back to default.'); } return $defaultAttributes; } diff --git a/apps/user_ldap/lib/GroupPluginManager.php b/apps/user_ldap/lib/GroupPluginManager.php index d99e17d7673..92bf0cb8888 100644 --- a/apps/user_ldap/lib/GroupPluginManager.php +++ b/apps/user_ldap/lib/GroupPluginManager.php @@ -24,6 +24,7 @@ namespace OCA\User_LDAP; use OCP\GroupInterface; +use Psr\Log\LoggerInterface; class GroupPluginManager { private int $respondToActions = 0; @@ -58,7 +59,7 @@ class GroupPluginManager { foreach ($this->which as $action => $v) { if ((bool)($respondToActions & $action)) { $this->which[$action] = $plugin; - \OC::$server->getLogger()->debug("Registered action ".$action." to plugin ".get_class($plugin), ['app' => 'user_ldap']); + \OCP\Server::get(LoggerInterface::class)->debug("Registered action ".$action." to plugin ".get_class($plugin), ['app' => 'user_ldap']); } } } diff --git a/apps/user_ldap/lib/Mapping/AbstractMapping.php b/apps/user_ldap/lib/Mapping/AbstractMapping.php index 3f05091a537..40bc8624c3c 100644 --- a/apps/user_ldap/lib/Mapping/AbstractMapping.php +++ b/apps/user_ldap/lib/Mapping/AbstractMapping.php @@ -30,6 +30,7 @@ use Doctrine\DBAL\Exception; use Doctrine\DBAL\Platforms\SqlitePlatform; use OCP\DB\IPreparedStatement; use OCP\DB\QueryBuilder\IQueryBuilder; +use Psr\Log\LoggerInterface; /** * Class AbstractMapping @@ -351,7 +352,7 @@ abstract class AbstractMapping { */ public function map($fdn, $name, $uuid) { if (mb_strlen($fdn) > 4000) { - \OC::$server->getLogger()->error( + \OCP\Server::get(LoggerInterface::class)->error( 'Cannot map, because the DN exceeds 4000 characters: {dn}', [ 'app' => 'user_ldap', diff --git a/apps/user_ldap/lib/UserPluginManager.php b/apps/user_ldap/lib/UserPluginManager.php index 516338f006b..527c6684103 100644 --- a/apps/user_ldap/lib/UserPluginManager.php +++ b/apps/user_ldap/lib/UserPluginManager.php @@ -26,6 +26,7 @@ namespace OCA\User_LDAP; use OC\User\Backend; +use Psr\Log\LoggerInterface; class UserPluginManager { private int $respondToActions = 0; @@ -62,12 +63,12 @@ class UserPluginManager { foreach ($this->which as $action => $v) { if (is_int($action) && (bool)($respondToActions & $action)) { $this->which[$action] = $plugin; - \OC::$server->getLogger()->debug("Registered action ".$action." to plugin ".get_class($plugin), ['app' => 'user_ldap']); + \OCP\Server::get(LoggerInterface::class)->debug("Registered action ".$action." to plugin ".get_class($plugin), ['app' => 'user_ldap']); } } if (method_exists($plugin, 'deleteUser')) { $this->which['deleteUser'] = $plugin; - \OC::$server->getLogger()->debug("Registered action deleteUser to plugin ".get_class($plugin), ['app' => 'user_ldap']); + \OCP\Server::get(LoggerInterface::class)->debug("Registered action deleteUser to plugin ".get_class($plugin), ['app' => 'user_ldap']); } } diff --git a/apps/user_ldap/tests/Integration/AbstractIntegrationTest.php b/apps/user_ldap/tests/Integration/AbstractIntegrationTest.php index 58475a2bea9..5ec04484bef 100644 --- a/apps/user_ldap/tests/Integration/AbstractIntegrationTest.php +++ b/apps/user_ldap/tests/Integration/AbstractIntegrationTest.php @@ -143,7 +143,7 @@ abstract class AbstractIntegrationTest { * initializes the Access test instance */ protected function initAccess() { - $this->access = new Access($this->connection, $this->ldap, $this->userManager, $this->helper, \OC::$server->getConfig(), \OC::$server->getLogger()); + $this->access = new Access($this->connection, $this->ldap, $this->userManager, $this->helper, \OC::$server->getConfig(), \OCP\Server::get(LoggerInterface::class)); } /** diff --git a/lib/private/Cache/File.php b/lib/private/Cache/File.php index 72fc95a802b..74e795cc377 100644 --- a/lib/private/Cache/File.php +++ b/lib/private/Cache/File.php @@ -60,7 +60,7 @@ class File implements ICache { $this->storage = new View('/' . $user->getUID() . '/cache'); return $this->storage; } else { - \OC::$server->get(LoggerInterface::class)->error('Can\'t get cache storage, user not logged in', ['app' => 'core']); + \OCP\Server::get(LoggerInterface::class)->error('Can\'t get cache storage, user not logged in', ['app' => 'core']); throw new \OC\ForbiddenException('Can\t get cache storage, user not logged in'); } } @@ -192,11 +192,11 @@ class File implements ICache { } } catch (\OCP\Lock\LockedException $e) { // ignore locked chunks - \OC::$server->getLogger()->debug('Could not cleanup locked chunk "' . $file . '"', ['app' => 'core']); + \OCP\Server::get(LoggerInterface::class)->debug('Could not cleanup locked chunk "' . $file . '"', ['app' => 'core']); } catch (\OCP\Files\ForbiddenException $e) { - \OC::$server->getLogger()->debug('Could not cleanup forbidden chunk "' . $file . '"', ['app' => 'core']); + \OCP\Server::get(LoggerInterface::class)->debug('Could not cleanup forbidden chunk "' . $file . '"', ['app' => 'core']); } catch (\OCP\Files\LockNotAcquiredException $e) { - \OC::$server->getLogger()->debug('Could not cleanup locked chunk "' . $file . '"', ['app' => 'core']); + \OCP\Server::get(LoggerInterface::class)->debug('Could not cleanup locked chunk "' . $file . '"', ['app' => 'core']); } } } diff --git a/lib/private/Files/Filesystem.php b/lib/private/Files/Filesystem.php index 9f0d89052be..c6a5513d5b7 100644 --- a/lib/private/Files/Filesystem.php +++ b/lib/private/Files/Filesystem.php @@ -48,6 +48,7 @@ use OCP\Files\Storage\IStorageFactory; use OCP\IUser; use OCP\IUserManager; use OCP\IUserSession; +use Psr\Log\LoggerInterface; class Filesystem { private static ?Mount\Manager $mounts = null; @@ -200,7 +201,7 @@ class Filesystem { */ public static function addStorageWrapper($wrapperName, $wrapper, $priority = 50) { if (self::$logWarningWhenAddingStorageWrapper) { - \OC::$server->getLogger()->warning("Storage wrapper '{wrapper}' was not registered via the 'OC_Filesystem - preSetup' hook which could cause potential problems.", [ + \OCP\Server::get(LoggerInterface::class)->warning("Storage wrapper '{wrapper}' was not registered via the 'OC_Filesystem - preSetup' hook which could cause potential problems.", [ 'wrapper' => $wrapperName, 'app' => 'filesystem', ]); diff --git a/lib/private/Files/ObjectStore/ObjectStoreStorage.php b/lib/private/Files/ObjectStore/ObjectStoreStorage.php index 3e0fbd15919..7eb284fc774 100644 --- a/lib/private/Files/ObjectStore/ObjectStoreStorage.php +++ b/lib/private/Files/ObjectStore/ObjectStoreStorage.php @@ -47,7 +47,7 @@ use OCP\Files\ObjectStore\IObjectStore; use OCP\Files\ObjectStore\IObjectStoreMultiPartUpload; use OCP\Files\Storage\IChunkedFileWrite; use OCP\Files\Storage\IStorage; -use OCP\ILogger; +use Psr\Log\LoggerInterface; class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFileWrite { use CopyDirectory; @@ -56,7 +56,7 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil protected string $id; private string $objectPrefix = 'urn:oid:'; - private ILogger $logger; + private LoggerInterface $logger; private bool $handleCopiesAsOwned; protected bool $validateWrites = true; @@ -84,7 +84,7 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil } $this->handleCopiesAsOwned = (bool)($params['handleCopiesAsOwned'] ?? false); - $this->logger = \OC::$server->getLogger(); + $this->logger = \OCP\Server::get(LoggerInterface::class); } public function mkdir($path, bool $force = false) { @@ -220,10 +220,13 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil $this->objectStore->deleteObject($this->getURN($entry->getId())); } catch (\Exception $ex) { if ($ex->getCode() !== 404) { - $this->logger->logException($ex, [ - 'app' => 'objectstore', - 'message' => 'Could not delete object ' . $this->getURN($entry->getId()) . ' for ' . $entry->getPath(), - ]); + $this->logger->error( + 'Could not delete object ' . $this->getURN($entry->getId()) . ' for ' . $entry->getPath(), + [ + 'app' => 'objectstore', + 'exception' => $ex, + ] + ); return false; } //removing from cache is ok as it does not exist in the objectstore anyway @@ -286,7 +289,7 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil return IteratorDirectory::wrap($files); } catch (\Exception $e) { - $this->logger->logException($e); + $this->logger->error($e->getMessage(), ['exception' => $e]); return false; } } @@ -336,16 +339,22 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil } return $handle; } catch (NotFoundException $e) { - $this->logger->logException($e, [ - 'app' => 'objectstore', - 'message' => 'Could not get object ' . $this->getURN($stat['fileid']) . ' for file ' . $path, - ]); + $this->logger->error( + 'Could not get object ' . $this->getURN($stat['fileid']) . ' for file ' . $path, + [ + 'app' => 'objectstore', + 'exception' => $e, + ] + ); throw $e; - } catch (\Exception $ex) { - $this->logger->logException($ex, [ - 'app' => 'objectstore', - 'message' => 'Could not get object ' . $this->getURN($stat['fileid']) . ' for file ' . $path, - ]); + } catch (\Exception $e) { + $this->logger->error( + 'Could not get object ' . $this->getURN($stat['fileid']) . ' for file ' . $path, + [ + 'app' => 'objectstore', + 'exception' => $e, + ] + ); return false; } } else { @@ -442,10 +451,13 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil ]; $this->getCache()->put($path, $stat); } catch (\Exception $ex) { - $this->logger->logException($ex, [ - 'app' => 'objectstore', - 'message' => 'Could not create object for ' . $path, - ]); + $this->logger->error( + 'Could not create object for ' . $path, + [ + 'app' => 'objectstore', + 'exception' => $ex, + ] + ); throw $ex; } } @@ -540,15 +552,21 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil * Else people lose access to existing files */ $this->getCache()->remove($uploadPath); - $this->logger->logException($ex, [ - 'app' => 'objectstore', - 'message' => 'Could not create object ' . $urn . ' for ' . $path, - ]); + $this->logger->error( + 'Could not create object ' . $urn . ' for ' . $path, + [ + 'app' => 'objectstore', + 'exception' => $ex, + ] + ); } else { - $this->logger->logException($ex, [ - 'app' => 'objectstore', - 'message' => 'Could not update object ' . $urn . ' for ' . $path, - ]); + $this->logger->error( + 'Could not update object ' . $urn . ' for ' . $path, + [ + 'app' => 'objectstore', + 'exception' => $ex, + ] + ); } throw $ex; // make this bubble up } @@ -713,10 +731,13 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil } } catch (S3MultipartUploadException|S3Exception $e) { $this->objectStore->abortMultipartUpload($urn, $writeToken); - $this->logger->logException($e, [ - 'app' => 'objectstore', - 'message' => 'Could not compete multipart upload ' . $urn . ' with uploadId ' . $writeToken, - ]); + $this->logger->error( + 'Could not compete multipart upload ' . $urn . ' with uploadId ' . $writeToken, + [ + 'app' => 'objectstore', + 'exception' => $e, + ] + ); throw new GenericFileException('Could not write chunked file'); } return $size; diff --git a/lib/private/L10N/L10N.php b/lib/private/L10N/L10N.php index ea4aa0527bb..c44e4f9cf49 100644 --- a/lib/private/L10N/L10N.php +++ b/lib/private/L10N/L10N.php @@ -30,6 +30,7 @@ namespace OC\L10N; use OCP\IL10N; use OCP\L10N\IFactory; +use Psr\Log\LoggerInterface; use Punic\Calendar; use Symfony\Component\Translation\IdentityTranslator; @@ -234,7 +235,7 @@ class L10N implements IL10N { $json = json_decode(file_get_contents($translationFile), true); if (!\is_array($json)) { $jsonError = json_last_error(); - \OC::$server->getLogger()->warning("Failed to load $translationFile - json error code: $jsonError", ['app' => 'l10n']); + \OCP\Server::get(LoggerInterface::class)->warning("Failed to load $translationFile - json error code: $jsonError", ['app' => 'l10n']); return false; } diff --git a/lib/private/Log/Rotate.php b/lib/private/Log/Rotate.php index efe548b7783..71965a12035 100644 --- a/lib/private/Log/Rotate.php +++ b/lib/private/Log/Rotate.php @@ -24,7 +24,9 @@ */ namespace OC\Log; +use OCP\IConfig; use OCP\Log\RotationTrait; +use Psr\Log\LoggerInterface; /** * This rotates the current logfile to a new name, this way the total log usage @@ -35,15 +37,15 @@ use OCP\Log\RotationTrait; class Rotate extends \OCP\BackgroundJob\Job { use RotationTrait; - public function run($dummy): void { - $systemConfig = \OC::$server->getSystemConfig(); - $this->filePath = $systemConfig->getValue('logfile', $systemConfig->getValue('datadirectory', \OC::$SERVERROOT . '/data') . '/nextcloud.log'); + public function run($argument): void { + $config = \OCP\Server::get(IConfig::class); + $this->filePath = $config->getSystemValueString('logfile', $config->getSystemValueString('datadirectory', \OC::$SERVERROOT . '/data') . '/nextcloud.log'); - $this->maxSize = \OC::$server->getConfig()->getSystemValueInt('log_rotate_size', 100 * 1024 * 1024); + $this->maxSize = $config->getSystemValueInt('log_rotate_size', 100 * 1024 * 1024); if ($this->shouldRotateBySize()) { $rotatedFile = $this->rotate(); $msg = 'Log file "'.$this->filePath.'" was over '.$this->maxSize.' bytes, moved to "'.$rotatedFile.'"'; - \OC::$server->getLogger()->info($msg, ['app' => Rotate::class]); + \OCP\Server::get(LoggerInterface::class)->info($msg, ['app' => Rotate::class]); } } } diff --git a/lib/private/Search.php b/lib/private/Search.php index b1e39843e49..9f1a0323aa3 100644 --- a/lib/private/Search.php +++ b/lib/private/Search.php @@ -30,6 +30,7 @@ namespace OC; use OCP\ISearch; use OCP\Search\PagedProvider; use OCP\Search\Provider; +use Psr\Log\LoggerInterface; /** * Provide an interface to all search providers @@ -65,7 +66,7 @@ class Search implements ISearch { $results = array_merge($results, $providerResults); } } else { - \OC::$server->getLogger()->warning('Ignoring Unknown search provider', ['provider' => $provider]); + \OCP\Server::get(LoggerInterface::class)->warning('Ignoring Unknown search provider', ['provider' => $provider]); } } return $results; diff --git a/lib/private/Share20/DefaultShareProvider.php b/lib/private/Share20/DefaultShareProvider.php index 55ac3eda644..b4ec16936f3 100644 --- a/lib/private/Share20/DefaultShareProvider.php +++ b/lib/private/Share20/DefaultShareProvider.php @@ -55,6 +55,7 @@ use OCP\Share\Exceptions\ShareNotFound; use OCP\Share\IAttributes; use OCP\Share\IShare; use OCP\Share\IShareProvider; +use Psr\Log\LoggerInterface; use function str_starts_with; /** @@ -1237,7 +1238,8 @@ class DefaultShareProvider implements IShareProvider { ) ); } else { - \OC::$server->getLogger()->logException(new \InvalidArgumentException('Default share provider tried to delete all shares for type: ' . $shareType)); + $e = new \InvalidArgumentException('Default share provider tried to delete all shares for type: ' . $shareType); + \OCP\Server::get(LoggerInterface::class)->error($e->getMessage(), ['exception' => $e]); return; } diff --git a/lib/private/Tags.php b/lib/private/Tags.php index 7b0c5093245..5f84b692def 100644 --- a/lib/private/Tags.php +++ b/lib/private/Tags.php @@ -35,7 +35,6 @@ use OC\Tagging\TagMapper; use OCP\DB\Exception; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IDBConnection; -use OCP\ILogger; use OCP\ITags; use OCP\Share_Backend; use Psr\Log\LoggerInterface; @@ -486,11 +485,13 @@ class Tags implements ITags { try { return $this->getIdsForTag(ITags::TAG_FAVORITE); } catch (\Exception $e) { - \OC::$server->getLogger()->logException($e, [ - 'message' => __METHOD__, - 'level' => ILogger::ERROR, - 'app' => 'core', - ]); + \OCP\Server::get(LoggerInterface::class)->error( + $e->getMessage(), + [ + 'app' => 'core', + 'exception' => $e, + ] + ); return []; } } @@ -549,7 +550,7 @@ class Tags implements ITags { try { $qb->executeStatement(); } catch (\Exception $e) { - \OC::$server->getLogger()->error($e->getMessage(), [ + \OCP\Server::get(LoggerInterface::class)->error($e->getMessage(), [ 'app' => 'core', 'exception' => $e, ]); diff --git a/lib/private/User/Manager.php b/lib/private/User/Manager.php index 705f5fbe66b..96edf624628 100644 --- a/lib/private/User/Manager.php +++ b/lib/private/User/Manager.php @@ -56,6 +56,7 @@ use OCP\User\Backend\ISearchKnownUsersBackend; use OCP\User\Events\BeforeUserCreatedEvent; use OCP\User\Events\UserCreatedEvent; use OCP\UserInterface; +use Psr\Log\LoggerInterface; /** * Class Manager @@ -235,7 +236,7 @@ class Manager extends PublicEmitter implements IUserManager { $result = $this->checkPasswordNoLogging($loginName, $password); if ($result === false) { - \OC::$server->getLogger()->warning('Login failed: \''. $loginName .'\' (Remote IP: \''. \OC::$server->getRequest()->getRemoteAddress(). '\')', ['app' => 'core']); + \OCP\Server::get(LoggerInterface::class)->warning('Login failed: \''. $loginName .'\' (Remote IP: \''. \OC::$server->getRequest()->getRemoteAddress(). '\')', ['app' => 'core']); } return $result; diff --git a/lib/public/AppFramework/App.php b/lib/public/AppFramework/App.php index 4d6e9177b78..f62c464ea55 100644 --- a/lib/public/AppFramework/App.php +++ b/lib/public/AppFramework/App.php @@ -38,6 +38,7 @@ use OC\AppFramework\Routing\RouteConfig; use OC\Route\Router; use OC\ServerContainer; use OCP\Route\IRouter; +use Psr\Log\LoggerInterface; /** * Class App @@ -98,8 +99,9 @@ class App { } if (!$setUpViaQuery && $applicationClassName !== \OCP\AppFramework\App::class) { - \OC::$server->getLogger()->logException($e, [ + \OCP\Server::get(LoggerInterface::class)->error($e->getMessage(), [ 'app' => $appName, + 'exception' => $e, ]); } } diff --git a/ocs/v1.php b/ocs/v1.php index 55e9f426aba..a2c8adeb982 100644 --- a/ocs/v1.php +++ b/ocs/v1.php @@ -42,6 +42,7 @@ if (\OCP\Util::needUpgrade() } use OCP\Security\Bruteforce\MaxDelayReached; +use Psr\Log\LoggerInterface; use Symfony\Component\Routing\Exception\MethodNotAllowedException; use Symfony\Component\Routing\Exception\ResourceNotFoundException; @@ -81,7 +82,7 @@ try { } catch (\OC\User\LoginException $e) { OC_API::respond(new \OC\OCS\Result(null, \OCP\AppFramework\OCSController::RESPOND_UNAUTHORISED, 'Unauthorised')); } catch (\Exception $e) { - \OC::$server->getLogger()->logException($e); + \OCP\Server::get(LoggerInterface::class)->error($e->getMessage(), ['exception' => $e]); OC_API::setContentType(); $format = \OC::$server->getRequest()->getParam('format', 'xml'); diff --git a/public.php b/public.php index 9f3ffcec5e9..2bf710c72fc 100644 --- a/public.php +++ b/public.php @@ -32,6 +32,8 @@ */ require_once __DIR__ . '/lib/versioncheck.php'; +use Psr\Log\LoggerInterface; + /** * @param $service * @return string @@ -103,10 +105,10 @@ try { $status = 503; } //show the user a detailed error page - \OC::$server->getLogger()->logException($ex, ['app' => 'public']); + \OCP\Server::get(LoggerInterface::class)->error($ex->getMessage(), ['app' => 'public', 'exception' => $ex]); OC_Template::printExceptionErrorPage($ex, $status); } catch (Error $ex) { //show the user a detailed error page - \OC::$server->getLogger()->logException($ex, ['app' => 'public']); + \OCP\Server::get(LoggerInterface::class)->error($ex->getMessage(), ['app' => 'public', 'exception' => $ex]); OC_Template::printExceptionErrorPage($ex, 500); } diff --git a/status.php b/status.php index 62eb978781c..99371bbe693 100644 --- a/status.php +++ b/status.php @@ -33,6 +33,8 @@ */ require_once __DIR__ . '/lib/versioncheck.php'; +use Psr\Log\LoggerInterface; + try { require_once __DIR__ . '/lib/base.php'; @@ -62,5 +64,5 @@ try { } } catch (Exception $ex) { http_response_code(500); - \OC::$server->getLogger()->logException($ex, ['app' => 'remote']); + \OCP\Server::get(LoggerInterface::class)->error($ex->getMessage(), ['app' => 'remote','exception' => $ex]); } -- 2.39.5