Skip to content

Commit 3a56ecc

Browse files
authored
Merge pull request #40565 from nextcloud/fix/remove-writelog
Remove deprecated methods Util::writeLog and DIContainer::log
2 parents f18e731 + f68d4f7 commit 3a56ecc

8 files changed

Lines changed: 25 additions & 66 deletions

File tree

core/Controller/SetupController.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,14 @@
3232
namespace OC\Core\Controller;
3333

3434
use OC\Setup;
35-
use OCP\ILogger;
35+
use Psr\Log\LoggerInterface;
3636

3737
class SetupController {
3838
private string $autoConfigFile;
3939

4040
public function __construct(
4141
protected Setup $setupHelper,
42+
protected LoggerInterface $logger,
4243
) {
4344
$this->autoConfigFile = \OC::$configDir.'autoconfig.php';
4445
}
@@ -78,7 +79,7 @@ public function run(array $post): void {
7879
}
7980
}
8081

81-
private function displaySetupForbidden() {
82+
private function displaySetupForbidden(): void {
8283
\OC_Template::printGuestPage('', 'installation_forbidden');
8384
}
8485

@@ -98,7 +99,7 @@ public function display($post): void {
9899
\OC_Template::printGuestPage('', 'installation', $parameters);
99100
}
100101

101-
private function finishSetup() {
102+
private function finishSetup(): void {
102103
if (file_exists($this->autoConfigFile)) {
103104
unlink($this->autoConfigFile);
104105
}
@@ -114,7 +115,7 @@ private function finishSetup() {
114115

115116
public function loadAutoConfig(array $post): array {
116117
if (file_exists($this->autoConfigFile)) {
117-
\OCP\Util::writeLog('core', 'Autoconfig file found, setting up Nextcloud…', ILogger::INFO);
118+
$this->logger->info('Autoconfig file found, setting up Nextcloud…');
118119
$AUTOCONFIG = [];
119120
include $this->autoConfigFile;
120121
$post = array_merge($post, $AUTOCONFIG);

lib/autoloader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
namespace OC;
3838

3939
use \OCP\AutoloadNotAllowedException;
40-
use OCP\ILogger;
4140
use OCP\ICache;
41+
use Psr\Log\LoggerInterface;
4242

4343
class Autoloader {
4444
/** @var bool */
@@ -105,7 +105,7 @@ public function findClass(string $class): array {
105105
* Remove "apps/" from inclusion path for smooth migration to multi app dir
106106
*/
107107
if (strpos(\OC::$CLASSPATH[$class], 'apps/') === 0) {
108-
\OCP\Util::writeLog('core', 'include path for class "' . $class . '" starts with "apps/"', ILogger::DEBUG);
108+
\OCP\Server::get(LoggerInterface::class)->debug('include path for class "' . $class . '" starts with "apps/"', ['app' => 'core']);
109109
$paths[] = str_replace('apps/', '', \OC::$CLASSPATH[$class]);
110110
}
111111
} elseif (strpos($class, 'OC_') === 0) {

lib/base.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -988,16 +988,17 @@ public static function handleRequest(): void {
988988
// Check if Nextcloud is installed or in maintenance (update) mode
989989
if (!$systemConfig->getValue('installed', false)) {
990990
\OC::$server->getSession()->clear();
991+
$logger = Server::get(\Psr\Log\LoggerInterface::class);
991992
$setupHelper = new OC\Setup(
992993
$systemConfig,
993994
Server::get(\bantu\IniGetWrapper\IniGetWrapper::class),
994995
Server::get(\OCP\L10N\IFactory::class)->get('lib'),
995996
Server::get(\OCP\Defaults::class),
996-
Server::get(\Psr\Log\LoggerInterface::class),
997+
$logger,
997998
Server::get(\OCP\Security\ISecureRandom::class),
998999
Server::get(\OC\Installer::class)
9991000
);
1000-
$controller = new OC\Core\Controller\SetupController($setupHelper);
1001+
$controller = new OC\Core\Controller\SetupController($setupHelper, $logger);
10011002
$controller->run($_POST);
10021003
exit();
10031004
}

lib/private/AppFramework/DependencyInjection/DIContainer.php

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -403,33 +403,6 @@ private function getUserId() {
403403
return $this->getServer()->getSession()->get('user_id');
404404
}
405405

406-
/**
407-
* @deprecated use the ILogger instead
408-
* @param string $message
409-
* @param string $level
410-
* @return mixed
411-
*/
412-
public function log($message, $level) {
413-
switch ($level) {
414-
case 'debug':
415-
$level = ILogger::DEBUG;
416-
break;
417-
case 'info':
418-
$level = ILogger::INFO;
419-
break;
420-
case 'warn':
421-
$level = ILogger::WARN;
422-
break;
423-
case 'fatal':
424-
$level = ILogger::FATAL;
425-
break;
426-
default:
427-
$level = ILogger::ERROR;
428-
break;
429-
}
430-
\OCP\Util::writeLog($this->getAppName(), $message, $level);
431-
}
432-
433406
/**
434407
* Register a capability
435408
*

lib/private/Tags.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ public function tagAs($objid, $tag) {
529529
if (is_string($tag) && !is_numeric($tag)) {
530530
$tag = trim($tag);
531531
if ($tag === '') {
532-
\OCP\Util::writeLog('core', __METHOD__.', Cannot add an empty tag', ILogger::DEBUG);
532+
$this->logger->debug(__METHOD__.', Cannot add an empty tag');
533533
return false;
534534
}
535535
if (!$this->hasTag($tag)) {
@@ -569,7 +569,7 @@ public function unTag($objid, $tag) {
569569
if (is_string($tag) && !is_numeric($tag)) {
570570
$tag = trim($tag);
571571
if ($tag === '') {
572-
\OCP\Util::writeLog('core', __METHOD__.', Tag name is empty', ILogger::DEBUG);
572+
$this->logger->debug(__METHOD__.', Tag name is empty');
573573
return false;
574574
}
575575
$tagId = $this->getTagId($tag);
@@ -609,8 +609,7 @@ public function delete($names) {
609609
$names = array_map('trim', $names);
610610
array_filter($names);
611611

612-
\OCP\Util::writeLog('core', __METHOD__ . ', before: '
613-
. print_r($this->tags, true), ILogger::DEBUG);
612+
$this->logger->debug(__METHOD__ . ', before: ' . print_r($this->tags, true));
614613
foreach ($names as $name) {
615614
$id = null;
616615

@@ -625,8 +624,7 @@ public function delete($names) {
625624
unset($this->tags[$key]);
626625
$this->mapper->delete($tag);
627626
} else {
628-
\OCP\Util::writeLog('core', __METHOD__ . 'Cannot delete tag ' . $name
629-
. ': not found.', ILogger::ERROR);
627+
$this->logger->error(__METHOD__ . 'Cannot delete tag ' . $name . ': not found.');
630628
}
631629
if (!is_null($id) && $id !== false) {
632630
try {

lib/private/legacy/OC_App.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
use OCP\App\ManagerEvent;
5757
use OCP\Authentication\IAlternativeLogin;
5858
use OCP\EventDispatcher\IEventDispatcher;
59-
use OCP\ILogger;
6059
use OC\AppFramework\Bootstrap\Coordinator;
6160
use OC\App\DependencyAnalyzer;
6261
use OC\App\Platform;
@@ -292,7 +291,7 @@ public static function getInstallPath() {
292291
}
293292
}
294293

295-
\OCP\Util::writeLog('core', 'No application directories are marked as writable.', ILogger::ERROR);
294+
\OCP\Server::get(LoggerInterface::class)->error('No application directories are marked as writable.', ['app' => 'core']);
296295
return null;
297296
}
298297

@@ -517,7 +516,7 @@ public static function getAllApps(): array {
517516

518517
foreach (OC::$APPSROOTS as $apps_dir) {
519518
if (!is_readable($apps_dir['path'])) {
520-
\OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], ILogger::WARN);
519+
\OCP\Server::get(LoggerInterface::class)->warning('unable to read app folder : ' . $apps_dir['path'], ['app' => 'core']);
521520
continue;
522521
}
523522
$dh = opendir($apps_dir['path']);
@@ -568,12 +567,12 @@ public function listAllApps(): array {
568567
if (array_search($app, $blacklist) === false) {
569568
$info = $appManager->getAppInfo($app, false, $langCode);
570569
if (!is_array($info)) {
571-
\OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', ILogger::ERROR);
570+
\OCP\Server::get(LoggerInterface::class)->error('Could not read app info file for app "' . $app . '"', ['app' => 'core']);
572571
continue;
573572
}
574573

575574
if (!isset($info['name'])) {
576-
\OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', ILogger::ERROR);
575+
\OCP\Server::get(LoggerInterface::class)->error('App id "' . $app . '" has no name in appinfo', ['app' => 'core']);
577576
continue;
578577
}
579578

@@ -870,11 +869,11 @@ public static function getStorage(string $appId) {
870869
}
871870
return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId);
872871
} else {
873-
\OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', ILogger::ERROR);
872+
\OCP\Server::get(LoggerInterface::class)->error('Can\'t get app storage, app ' . $appId . ', user not logged in', ['app' => 'core']);
874873
return false;
875874
}
876875
} else {
877-
\OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', ILogger::ERROR);
876+
\OCP\Server::get(LoggerInterface::class)->error('Can\'t get app storage, app ' . $appId . ' not enabled', ['app' => 'core']);
878877
return false;
879878
}
880879
}

lib/private/legacy/OC_User.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@
3838

3939
use OC\User\LoginException;
4040
use OCP\EventDispatcher\IEventDispatcher;
41-
use OCP\ILogger;
4241
use OCP\IUserManager;
4342
use OCP\User\Events\BeforeUserLoggedInEvent;
4443
use OCP\User\Events\UserLoggedInEvent;
44+
use Psr\Log\LoggerInterface;
4545

4646
/**
4747
* This class provides wrapper methods for user management. Multiple backends are
@@ -93,7 +93,7 @@ public static function useBackend($backend = 'database') {
9393
case 'database':
9494
case 'mysql':
9595
case 'sqlite':
96-
\OCP\Util::writeLog('core', 'Adding user backend ' . $backend . '.', ILogger::DEBUG);
96+
\OCP\Server::get(LoggerInterface::class)->debug('Adding user backend ' . $backend . '.', ['app' => 'core']);
9797
self::$_usedBackends[$backend] = new \OC\User\Database();
9898
\OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]);
9999
break;
@@ -102,7 +102,7 @@ public static function useBackend($backend = 'database') {
102102
\OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]);
103103
break;
104104
default:
105-
\OCP\Util::writeLog('core', 'Adding default user backend ' . $backend . '.', ILogger::DEBUG);
105+
\OCP\Server::get(LoggerInterface::class)->debug('Adding default user backend ' . $backend . '.', ['app' => 'core']);
106106
$className = 'OC_USER_' . strtoupper($backend);
107107
self::$_usedBackends[$backend] = new $className();
108108
\OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]);
@@ -147,10 +147,10 @@ public static function setupBackends() {
147147
self::useBackend($backend);
148148
self::$_setupedBackends[] = $i;
149149
} else {
150-
\OCP\Util::writeLog('core', 'User backend ' . $class . ' already initialized.', ILogger::DEBUG);
150+
\OCP\Server::get(LoggerInterface::class)->debug('User backend ' . $class . ' already initialized.', ['app' => 'core']);
151151
}
152152
} else {
153-
\OCP\Util::writeLog('core', 'User backend ' . $class . ' not found.', ILogger::ERROR);
153+
\OCP\Server::get(LoggerInterface::class)->error('User backend ' . $class . ' not found.', ['app' => 'core']);
154154
}
155155
}
156156
}

lib/public/Util.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -104,19 +104,6 @@ public static function getChannel() {
104104
return \OC_Util::getChannel();
105105
}
106106

107-
/**
108-
* write a message in the log
109-
* @param string $app
110-
* @param string $message
111-
* @param int $level
112-
* @since 4.0.0
113-
* @deprecated 13.0.0 use log of \OCP\ILogger
114-
*/
115-
public static function writeLog($app, $message, $level) {
116-
$context = ['app' => $app];
117-
\OC::$server->getLogger()->log($level, $message, $context);
118-
}
119-
120107
/**
121108
* check if sharing is disabled for the current user
122109
*

0 commit comments

Comments
 (0)