diff options
author | Côme Chilliet <come.chilliet@nextcloud.com> | 2024-02-08 15:47:39 +0100 |
---|---|---|
committer | Côme Chilliet <91878298+come-nc@users.noreply.github.com> | 2024-02-13 17:32:30 +0100 |
commit | c0ce272e9c3a94ff98081c4f90a31ca611d28323 (patch) | |
tree | e92ba163d28ac3eb888a95718a85a78909cdc7c7 /lib | |
parent | 8822b16d37de1d1a3cec959d184261152c42ae41 (diff) | |
download | nextcloud-server-c0ce272e9c3a94ff98081c4f90a31ca611d28323.tar.gz nextcloud-server-c0ce272e9c3a94ff98081c4f90a31ca611d28323.zip |
chore: Migrate away from OC::$server->getLogger
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Cache/File.php | 8 | ||||
-rw-r--r-- | lib/private/Files/Filesystem.php | 3 | ||||
-rw-r--r-- | lib/private/Files/ObjectStore/ObjectStoreStorage.php | 87 | ||||
-rw-r--r-- | lib/private/L10N/L10N.php | 3 | ||||
-rw-r--r-- | lib/private/Log/Rotate.php | 12 | ||||
-rw-r--r-- | lib/private/Search.php | 3 | ||||
-rw-r--r-- | lib/private/Share20/DefaultShareProvider.php | 4 | ||||
-rw-r--r-- | lib/private/Tags.php | 15 | ||||
-rw-r--r-- | lib/private/User/Manager.php | 3 | ||||
-rw-r--r-- | lib/public/AppFramework/App.php | 4 |
10 files changed, 87 insertions, 55 deletions
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, ]); } } |