From 504a8ea97017049ec0b42ec19cb4e51537368246 Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Wed, 31 May 2023 14:42:04 +0200 Subject: [PATCH 1/3] chore: Replace \OCP\Util::writeLog with \OCP\Log\logger calls Signed-off-by: Christoph Wurst --- core/Controller/SetupController.php | 4 ++-- lib/autoloader.php | 4 ++-- .../DependencyInjection/DIContainer.php | 5 +++-- lib/private/Tags.php | 13 +++++++------ lib/private/legacy/OC_App.php | 14 +++++++------- lib/private/legacy/OC_User.php | 10 +++++----- 6 files changed, 26 insertions(+), 24 deletions(-) diff --git a/core/Controller/SetupController.php b/core/Controller/SetupController.php index 69c3b2f2a2394..63afb94a67ee2 100644 --- a/core/Controller/SetupController.php +++ b/core/Controller/SetupController.php @@ -32,7 +32,7 @@ namespace OC\Core\Controller; use OC\Setup; -use OCP\ILogger; +use function OCP\Log\logger; class SetupController { private string $autoConfigFile; @@ -114,7 +114,7 @@ private function finishSetup() { public function loadAutoConfig(array $post): array { if (file_exists($this->autoConfigFile)) { - \OCP\Util::writeLog('core', 'Autoconfig file found, setting up Nextcloud…', ILogger::INFO); + logger('core')->info('Autoconfig file found, setting up Nextcloud…'); $AUTOCONFIG = []; include $this->autoConfigFile; $post = array_merge($post, $AUTOCONFIG); diff --git a/lib/autoloader.php b/lib/autoloader.php index a29b9aece7982..abb35d558a179 100644 --- a/lib/autoloader.php +++ b/lib/autoloader.php @@ -37,8 +37,8 @@ namespace OC; use \OCP\AutoloadNotAllowedException; -use OCP\ILogger; use OCP\ICache; +use function OCP\Log\logger; class Autoloader { /** @var bool */ @@ -105,7 +105,7 @@ public function findClass(string $class): array { * Remove "apps/" from inclusion path for smooth migration to multi app dir */ if (strpos(\OC::$CLASSPATH[$class], 'apps/') === 0) { - \OCP\Util::writeLog('core', 'include path for class "' . $class . '" starts with "apps/"', ILogger::DEBUG); + logger('core')->debug('Include path for class "' . $class . '" starts with "apps/"'); $paths[] = str_replace('apps/', '', \OC::$CLASSPATH[$class]); } } elseif (strpos($class, 'OC_') === 0) { diff --git a/lib/private/AppFramework/DependencyInjection/DIContainer.php b/lib/private/AppFramework/DependencyInjection/DIContainer.php index a012d1e8ea69f..b2822e9b0b069 100644 --- a/lib/private/AppFramework/DependencyInjection/DIContainer.php +++ b/lib/private/AppFramework/DependencyInjection/DIContainer.php @@ -75,6 +75,7 @@ use OCP\Security\Bruteforce\IThrottler; use Psr\Container\ContainerInterface; use Psr\Log\LoggerInterface; +use function OCP\Log\logger; /** * @deprecated 20.0.0 @@ -404,7 +405,7 @@ private function getUserId() { } /** - * @deprecated use the ILogger instead + * @deprecated use the LoggerInterface instead * @param string $message * @param string $level * @return mixed @@ -427,7 +428,7 @@ public function log($message, $level) { $level = ILogger::ERROR; break; } - \OCP\Util::writeLog($this->getAppName(), $message, $level); + logger($this->getAppName())->log($level, $message); } /** diff --git a/lib/private/Tags.php b/lib/private/Tags.php index 8da1e7edc3b8a..2acbc8d0905c7 100644 --- a/lib/private/Tags.php +++ b/lib/private/Tags.php @@ -39,6 +39,7 @@ use OCP\ITags; use OCP\Share_Backend; use Psr\Log\LoggerInterface; +use function OCP\Log\logger; class Tags implements ITags { /** @@ -529,7 +530,7 @@ public function tagAs($objid, $tag) { if (is_string($tag) && !is_numeric($tag)) { $tag = trim($tag); if ($tag === '') { - \OCP\Util::writeLog('core', __METHOD__.', Cannot add an empty tag', ILogger::DEBUG); + logger('core')->debug(__METHOD__.', Cannot add an empty tag'); return false; } if (!$this->hasTag($tag)) { @@ -569,7 +570,7 @@ public function unTag($objid, $tag) { if (is_string($tag) && !is_numeric($tag)) { $tag = trim($tag); if ($tag === '') { - \OCP\Util::writeLog('core', __METHOD__.', Tag name is empty', ILogger::DEBUG); + logger('core')->debug(__METHOD__.', Tag name is empty'); return false; } $tagId = $this->getTagId($tag); @@ -609,8 +610,8 @@ public function delete($names) { $names = array_map('trim', $names); array_filter($names); - \OCP\Util::writeLog('core', __METHOD__ . ', before: ' - . print_r($this->tags, true), ILogger::DEBUG); + logger('core')->debug(__METHOD__ . ', before: ' + . print_r($this->tags, true)); foreach ($names as $name) { $id = null; @@ -625,8 +626,8 @@ public function delete($names) { unset($this->tags[$key]); $this->mapper->delete($tag); } else { - \OCP\Util::writeLog('core', __METHOD__ . 'Cannot delete tag ' . $name - . ': not found.', ILogger::ERROR); + logger('core')->error(__METHOD__ . 'Cannot delete tag ' . $name + . ': not found.'); } if (!is_null($id) && $id !== false) { try { diff --git a/lib/private/legacy/OC_App.php b/lib/private/legacy/OC_App.php index ac449a62a4ffb..9f79c5e974fee 100644 --- a/lib/private/legacy/OC_App.php +++ b/lib/private/legacy/OC_App.php @@ -56,7 +56,6 @@ use OCP\App\ManagerEvent; use OCP\Authentication\IAlternativeLogin; use OCP\EventDispatcher\IEventDispatcher; -use OCP\ILogger; use OC\AppFramework\Bootstrap\Coordinator; use OC\App\DependencyAnalyzer; use OC\App\Platform; @@ -66,6 +65,7 @@ use OC\Repair\Events\RepairErrorEvent; use Psr\Container\ContainerExceptionInterface; use Psr\Log\LoggerInterface; +use function OCP\Log\logger; /** * This class manages the apps. It allows them to register and integrate in the @@ -292,7 +292,7 @@ public static function getInstallPath() { } } - \OCP\Util::writeLog('core', 'No application directories are marked as writable.', ILogger::ERROR); + logger('core')->error('No application directories are marked as writable.'); return null; } @@ -517,7 +517,7 @@ public static function getAllApps(): array { foreach (OC::$APPSROOTS as $apps_dir) { if (!is_readable($apps_dir['path'])) { - \OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], ILogger::WARN); + logger('core')->warning('Unable to read app folder: ' . $apps_dir['path']); continue; } $dh = opendir($apps_dir['path']); @@ -568,12 +568,12 @@ public function listAllApps(): array { if (array_search($app, $blacklist) === false) { $info = $appManager->getAppInfo($app, false, $langCode); if (!is_array($info)) { - \OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', ILogger::ERROR); + logger('core')->error('Could not read app info file for app "' . $app . '"'); continue; } if (!isset($info['name'])) { - \OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', ILogger::ERROR); + logger('core')->error('App id "' . $app . '" has no name in appinfo'); continue; } @@ -870,11 +870,11 @@ public static function getStorage(string $appId) { } return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId); } else { - \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', ILogger::ERROR); + logger('core')->error('Can\'t get app storage, app ' . $appId . ', user not logged in'); return false; } } else { - \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', ILogger::ERROR); + logger('core')->error('Can\'t get app storage, app ' . $appId . ' not enabled'); return false; } } diff --git a/lib/private/legacy/OC_User.php b/lib/private/legacy/OC_User.php index caa4f5dca6512..7ddc4e087a149 100644 --- a/lib/private/legacy/OC_User.php +++ b/lib/private/legacy/OC_User.php @@ -38,10 +38,10 @@ use OC\User\LoginException; use OCP\EventDispatcher\IEventDispatcher; -use OCP\ILogger; use OCP\IUserManager; use OCP\User\Events\BeforeUserLoggedInEvent; use OCP\User\Events\UserLoggedInEvent; +use function OCP\Log\logger; /** * This class provides wrapper methods for user management. Multiple backends are @@ -93,7 +93,7 @@ public static function useBackend($backend = 'database') { case 'database': case 'mysql': case 'sqlite': - \OCP\Util::writeLog('core', 'Adding user backend ' . $backend . '.', ILogger::DEBUG); + logger('core')->debug('Adding user backend ' . $backend . '.'); self::$_usedBackends[$backend] = new \OC\User\Database(); \OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]); break; @@ -102,7 +102,7 @@ public static function useBackend($backend = 'database') { \OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]); break; default: - \OCP\Util::writeLog('core', 'Adding default user backend ' . $backend . '.', ILogger::DEBUG); + logger('core')->debug('Adding default user backend ' . $backend . '.'); $className = 'OC_USER_' . strtoupper($backend); self::$_usedBackends[$backend] = new $className(); \OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]); @@ -147,10 +147,10 @@ public static function setupBackends() { self::useBackend($backend); self::$_setupedBackends[] = $i; } else { - \OCP\Util::writeLog('core', 'User backend ' . $class . ' already initialized.', ILogger::DEBUG); + logger('core')->debug('User backend ' . $class . ' already initialized.'); } } else { - \OCP\Util::writeLog('core', 'User backend ' . $class . ' not found.', ILogger::ERROR); + logger('core')->error('User backend ' . $class . ' not found.'); } } } From 76f017a13f82bd0709778742e914b570c4bd4ab3 Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Wed, 31 May 2023 14:43:45 +0200 Subject: [PATCH 2/3] chore(ocp)!: Drop \OCP\Util::writeLog Signed-off-by: Christoph Wurst --- lib/public/Util.php | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/lib/public/Util.php b/lib/public/Util.php index 781aa87d66b79..cabb84c0cf663 100644 --- a/lib/public/Util.php +++ b/lib/public/Util.php @@ -104,19 +104,6 @@ public static function getChannel() { return \OC_Util::getChannel(); } - /** - * write a message in the log - * @param string $app - * @param string $message - * @param int $level - * @since 4.0.0 - * @deprecated 13.0.0 use log of \OCP\ILogger - */ - public static function writeLog($app, $message, $level) { - $context = ['app' => $app]; - \OC::$server->getLogger()->log($level, $message, $context); - } - /** * check if sharing is disabled for the current user * From e2faf6da0a3d4789f9277f90da1576a10cc64aee Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Wed, 31 May 2023 14:54:07 +0200 Subject: [PATCH 3/3] chore(appframework): Remove deprecated and unused DIContainer::log Signed-off-by: Christoph Wurst --- .../DependencyInjection/DIContainer.php | 28 ------------------- 1 file changed, 28 deletions(-) diff --git a/lib/private/AppFramework/DependencyInjection/DIContainer.php b/lib/private/AppFramework/DependencyInjection/DIContainer.php index b2822e9b0b069..c342ea236e2fd 100644 --- a/lib/private/AppFramework/DependencyInjection/DIContainer.php +++ b/lib/private/AppFramework/DependencyInjection/DIContainer.php @@ -75,7 +75,6 @@ use OCP\Security\Bruteforce\IThrottler; use Psr\Container\ContainerInterface; use Psr\Log\LoggerInterface; -use function OCP\Log\logger; /** * @deprecated 20.0.0 @@ -404,33 +403,6 @@ private function getUserId() { return $this->getServer()->getSession()->get('user_id'); } - /** - * @deprecated use the LoggerInterface instead - * @param string $message - * @param string $level - * @return mixed - */ - public function log($message, $level) { - switch ($level) { - case 'debug': - $level = ILogger::DEBUG; - break; - case 'info': - $level = ILogger::INFO; - break; - case 'warn': - $level = ILogger::WARN; - break; - case 'fatal': - $level = ILogger::FATAL; - break; - default: - $level = ILogger::ERROR; - break; - } - logger($this->getAppName())->log($level, $message); - } - /** * Register a capability *