Skip to content

Commit 459202d

Browse files
authored
Merge pull request #31752 from nextcloud/fix/remove-still-more-ilogger
Move away from deprecated ILogger
2 parents 106d5f9 + 8184e35 commit 459202d

21 files changed

Lines changed: 109 additions & 230 deletions

File tree

lib/composer/composer/autoload_classmap.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1501,7 +1501,6 @@
15011501
'OC\\Share20\\UserRemovedListener' => $baseDir . '/lib/private/Share20/UserRemovedListener.php',
15021502
'OC\\Share\\Constants' => $baseDir . '/lib/private/Share/Constants.php',
15031503
'OC\\Share\\Helper' => $baseDir . '/lib/private/Share/Helper.php',
1504-
'OC\\Share\\SearchResultSorter' => $baseDir . '/lib/private/Share/SearchResultSorter.php',
15051504
'OC\\Share\\Share' => $baseDir . '/lib/private/Share/Share.php',
15061505
'OC\\StreamImage' => $baseDir . '/lib/private/StreamImage.php',
15071506
'OC\\Streamer' => $baseDir . '/lib/private/Streamer.php',

lib/composer/composer/autoload_static.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1530,7 +1530,6 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
15301530
'OC\\Share20\\UserRemovedListener' => __DIR__ . '/../../..' . '/lib/private/Share20/UserRemovedListener.php',
15311531
'OC\\Share\\Constants' => __DIR__ . '/../../..' . '/lib/private/Share/Constants.php',
15321532
'OC\\Share\\Helper' => __DIR__ . '/../../..' . '/lib/private/Share/Helper.php',
1533-
'OC\\Share\\SearchResultSorter' => __DIR__ . '/../../..' . '/lib/private/Share/SearchResultSorter.php',
15341533
'OC\\Share\\Share' => __DIR__ . '/../../..' . '/lib/private/Share/Share.php',
15351534
'OC\\StreamImage' => __DIR__ . '/../../..' . '/lib/private/StreamImage.php',
15361535
'OC\\Streamer' => __DIR__ . '/../../..' . '/lib/private/Streamer.php',

lib/private/Cache/File.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
use OC\Files\Filesystem;
3333
use OC\Files\View;
3434
use OCP\ICache;
35-
use OCP\ILogger;
3635
use OCP\Security\ISecureRandom;
36+
use Psr\Log\LoggerInterface;
3737

3838
class File implements ICache {
3939

@@ -61,7 +61,7 @@ protected function getStorage() {
6161
$this->storage = new View('/' . $user->getUID() . '/cache');
6262
return $this->storage;
6363
} else {
64-
\OCP\Util::writeLog('core', 'Can\'t get cache storage, user not logged in', ILogger::ERROR);
64+
\OC::$server->get(LoggerInterface::class)->error('Can\'t get cache storage, user not logged in', ['app' => 'core']);
6565
throw new \OC\ForbiddenException('Can\t get cache storage, user not logged in');
6666
}
6767
}

lib/private/Dashboard/Manager.php

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
use OCP\AppFramework\QueryException;
3131
use OCP\Dashboard\IManager;
3232
use OCP\Dashboard\IWidget;
33-
use OCP\ILogger;
3433
use OCP\IServerContainer;
3534
use Throwable;
35+
use Psr\Log\LoggerInterface;
3636

3737
class Manager implements IManager {
3838

@@ -72,10 +72,10 @@ public function loadLazyPanels(): void {
7272
* There is a circular dependency between the logger and the registry, so
7373
* we can not inject it. Thus the static call.
7474
*/
75-
\OC::$server->getLogger()->logException($e, [
76-
'message' => 'Could not load lazy dashbaord widget: ' . $e->getMessage(),
77-
'level' => ILogger::FATAL,
78-
]);
75+
\OC::$server->get(LoggerInterface::class)->critical(
76+
'Could not load lazy dashboard widget: ' . $e->getMessage(),
77+
['excepiton' => $e]
78+
);
7979
}
8080
/**
8181
* Try to register the loaded reporter. Theoretically it could be of a wrong
@@ -88,10 +88,10 @@ public function loadLazyPanels(): void {
8888
* There is a circular dependency between the logger and the registry, so
8989
* we can not inject it. Thus the static call.
9090
*/
91-
\OC::$server->getLogger()->logException($e, [
92-
'message' => 'Could not register lazy dashboard widget: ' . $e->getMessage(),
93-
'level' => ILogger::FATAL,
94-
]);
91+
\OC::$server->get(LoggerInterface::class)->critical(
92+
'Could not register lazy dashboard widget: ' . $e->getMessage(),
93+
['excepiton' => $e]
94+
);
9595
}
9696

9797
try {
@@ -100,16 +100,19 @@ public function loadLazyPanels(): void {
100100
$endTime = microtime(true);
101101
$duration = $endTime - $startTime;
102102
if ($duration > 1) {
103-
\OC::$server->getLogger()->error('Dashboard widget {widget} took {duration} seconds to load.', [
104-
'widget' => $widget->getId(),
105-
'duration' => round($duration, 2),
106-
]);
103+
\OC::$server->get(LoggerInterface::class)->error(
104+
'Dashboard widget {widget} took {duration} seconds to load.',
105+
[
106+
'widget' => $widget->getId(),
107+
'duration' => round($duration, 2),
108+
]
109+
);
107110
}
108111
} catch (Throwable $e) {
109-
\OC::$server->getLogger()->logException($e, [
110-
'message' => 'Error during dashboard widget loading: ' . $e->getMessage(),
111-
'level' => ILogger::FATAL,
112-
]);
112+
\OC::$server->get(LoggerInterface::class)->critical(
113+
'Error during dashboard widget loading: ' . $e->getMessage(),
114+
['excepiton' => $e]
115+
);
113116
}
114117
}
115118
$this->lazyWidgets = [];

lib/private/DateTimeZone.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626

2727
use OCP\IConfig;
2828
use OCP\IDateTimeZone;
29-
use OCP\ILogger;
3029
use OCP\ISession;
30+
use Psr\Log\LoggerInterface;
3131

3232
class DateTimeZone implements IDateTimeZone {
3333
/** @var IConfig */
@@ -65,7 +65,7 @@ public function getTimeZone($timestamp = false) {
6565
try {
6666
return new \DateTimeZone($timeZone);
6767
} catch (\Exception $e) {
68-
\OCP\Util::writeLog('datetimezone', 'Failed to created DateTimeZone "' . $timeZone . "'", ILogger::DEBUG);
68+
\OC::$server->get(LoggerInterface::class)->debug('Failed to created DateTimeZone "' . $timeZone . '"', ['app' => 'datetimezone']);
6969
return new \DateTimeZone($this->getDefaultTimeZone());
7070
}
7171
}
@@ -110,7 +110,7 @@ protected function guessTimeZoneFromOffset($offset, $timestamp) {
110110
}
111111

112112
// No timezone found, fallback to UTC
113-
\OCP\Util::writeLog('datetimezone', 'Failed to find DateTimeZone for offset "' . $offset . "'", ILogger::DEBUG);
113+
\OC::$server->get(LoggerInterface::class)->debug('Failed to find DateTimeZone for offset "' . $offset . '"', ['app' => 'datetimezone']);
114114
return new \DateTimeZone($this->getDefaultTimeZone());
115115
}
116116
}

lib/private/Files/Cache/Scanner.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@
3636
namespace OC\Files\Cache;
3737

3838
use Doctrine\DBAL\Exception;
39-
use OC\Files\Storage\Wrapper\Jail;
40-
use OC\Files\Storage\Wrapper\Encoding;
41-
use OC\Hooks\BasicEmitter;
4239
use OCP\Files\Cache\IScanner;
4340
use OCP\Files\ForbiddenException;
4441
use OCP\Files\Storage\IReliableEtagStorage;
45-
use OCP\ILogger;
4642
use OCP\Lock\ILockingProvider;
43+
use OC\Files\Storage\Wrapper\Encoding;
44+
use OC\Files\Storage\Wrapper\Jail;
45+
use OC\Hooks\BasicEmitter;
46+
use Psr\Log\LoggerInterface;
4747

4848
/**
4949
* Class Scanner
@@ -115,7 +115,7 @@ public function setUseTransactions($useTransactions) {
115115
protected function getData($path) {
116116
$data = $this->storage->getMetaData($path);
117117
if (is_null($data)) {
118-
\OCP\Util::writeLog(Scanner::class, "!!! Path '$path' is not accessible or present !!!", ILogger::DEBUG);
118+
\OC::$server->get(LoggerInterface::class)->debug("!!! Path '$path' is not accessible or present !!!", ['app' => 'core']);
119119
}
120120
return $data;
121121
}
@@ -425,7 +425,7 @@ private function handleChildren($path, $recursive, $reuse, $folderId, $lock, &$s
425425
$file = trim(\OC\Files\Filesystem::normalizePath($originalFile), '/');
426426
if (trim($originalFile, '/') !== $file) {
427427
// encoding mismatch, might require compatibility wrapper
428-
\OC::$server->getLogger()->debug('Scanner: Skipping non-normalized file name "'. $originalFile . '" in path "' . $path . '".', ['app' => 'core']);
428+
\OC::$server->get(LoggerInterface::class)->debug('Scanner: Skipping non-normalized file name "'. $originalFile . '" in path "' . $path . '".', ['app' => 'core']);
429429
$this->emit('\OC\Files\Cache\Scanner', 'normalizedNameMismatch', [$path ? $path . '/' . $originalFile : $originalFile]);
430430
// skip this entry
431431
continue;
@@ -456,10 +456,9 @@ private function handleChildren($path, $recursive, $reuse, $folderId, $lock, &$s
456456
\OC::$server->getDatabaseConnection()->rollback();
457457
\OC::$server->getDatabaseConnection()->beginTransaction();
458458
}
459-
\OC::$server->getLogger()->logException($ex, [
460-
'message' => 'Exception while scanning file "' . $child . '"',
461-
'level' => ILogger::DEBUG,
459+
\OC::$server->get(LoggerInterface::class)->debug('Exception while scanning file "' . $child . '"', [
462460
'app' => 'core',
461+
'exception' => $ex,
463462
]);
464463
$exceptionOccurred = true;
465464
} catch (\OCP\Lock\LockedException $e) {

lib/private/Files/Mount/MountPoint.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
use OC\Files\Storage\StorageFactory;
3636
use OCP\Files\Mount\IMountPoint;
3737
use OCP\Files\Storage\IStorageFactory;
38-
use OCP\ILogger;
38+
use Psr\Log\LoggerInterface;
3939

4040
class MountPoint implements IMountPoint {
4141
/**
@@ -173,12 +173,12 @@ private function createStorage() {
173173
// the root storage could not be initialized, show the user!
174174
throw new \Exception('The root storage could not be initialized. Please contact your local administrator.', $exception->getCode(), $exception);
175175
} else {
176-
\OC::$server->getLogger()->logException($exception, ['level' => ILogger::ERROR]);
176+
\OC::$server->get(LoggerInterface::class)->error($exception->getMessage(), ['exception' => $exception]);
177177
}
178178
return;
179179
}
180180
} else {
181-
\OCP\Util::writeLog('core', 'storage backend ' . $this->class . ' not found', ILogger::ERROR);
181+
\OC::$server->get(LoggerInterface::class)->error('Storage backend ' . $this->class . ' not found', ['app' => 'core']);
182182
$this->invalidStorage = true;
183183
return;
184184
}

lib/private/Files/Mount/ObjectHomeMountProvider.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
use OCP\Files\Config\IHomeMountProvider;
2828
use OCP\Files\Storage\IStorageFactory;
2929
use OCP\IConfig;
30-
use OCP\ILogger;
3130
use OCP\IUser;
31+
use Psr\Log\LoggerInterface;
3232

3333
/**
3434
* Mount provider for object store home storages
@@ -80,7 +80,7 @@ private function getSingleBucketObjectStoreConfig(IUser $user) {
8080

8181
// sanity checks
8282
if (empty($config['class'])) {
83-
\OCP\Util::writeLog('files', 'No class given for objectstore', ILogger::ERROR);
83+
\OC::$server->get(LoggerInterface::class)->error('No class given for objectstore', ['app' => 'files']);
8484
}
8585
if (!isset($config['arguments'])) {
8686
$config['arguments'] = [];
@@ -105,7 +105,7 @@ private function getMultiBucketObjectStoreConfig(IUser $user) {
105105

106106
// sanity checks
107107
if (empty($config['class'])) {
108-
\OCP\Util::writeLog('files', 'No class given for objectstore', ILogger::ERROR);
108+
\OC::$server->get(LoggerInterface::class)->error('No class given for objectstore', ['app' => 'files']);
109109
}
110110
if (!isset($config['arguments'])) {
111111
$config['arguments'] = [];

lib/private/Files/ObjectStore/S3ConnectionTrait.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
use GuzzleHttp\Promise;
4040
use GuzzleHttp\Promise\RejectedPromise;
4141
use OCP\ICertificateManager;
42-
use OCP\ILogger;
42+
use Psr\Log\LoggerInterface;
4343

4444
trait S3ConnectionTrait {
4545
/** @var array */
@@ -150,13 +150,13 @@ public function getConnection() {
150150
$this->connection = new S3Client($options);
151151

152152
if (!$this->connection::isBucketDnsCompatible($this->bucket)) {
153-
$logger = \OC::$server->getLogger();
153+
$logger = \OC::$server->get(LoggerInterface::class);
154154
$logger->debug('Bucket "' . $this->bucket . '" This bucket name is not dns compatible, it may contain invalid characters.',
155155
['app' => 'objectstore']);
156156
}
157157

158158
if ($this->params['verify_bucket_exists'] && !$this->connection->doesBucketExist($this->bucket)) {
159-
$logger = \OC::$server->getLogger();
159+
$logger = \OC::$server->get(LoggerInterface::class);
160160
try {
161161
$logger->info('Bucket "' . $this->bucket . '" does not exist - creating it.', ['app' => 'objectstore']);
162162
if (!$this->connection::isBucketDnsCompatible($this->bucket)) {
@@ -165,9 +165,8 @@ public function getConnection() {
165165
$this->connection->createBucket(['Bucket' => $this->bucket]);
166166
$this->testTimeout();
167167
} catch (S3Exception $e) {
168-
$logger->logException($e, [
169-
'message' => 'Invalid remote storage.',
170-
'level' => ILogger::DEBUG,
168+
$logger->debug('Invalid remote storage.', [
169+
'exception' => $e,
171170
'app' => 'objectstore',
172171
]);
173172
throw new \Exception('Creation of bucket "' . $this->bucket . '" failed. ' . $e->getMessage());

lib/private/Files/Storage/Common.php

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@
6161
use OCP\Files\Storage\ILockingStorage;
6262
use OCP\Files\Storage\IStorage;
6363
use OCP\Files\Storage\IWriteStreamStorage;
64-
use OCP\ILogger;
6564
use OCP\Lock\ILockingProvider;
6665
use OCP\Lock\LockedException;
66+
use Psr\Log\LoggerInterface;
6767

6868
/**
6969
* Storage backend class for providing common filesystem operation methods
@@ -89,7 +89,9 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage {
8989
protected $mountOptions = [];
9090
protected $owner = null;
9191

92+
/** @var ?bool */
9293
private $shouldLogLocks = null;
94+
/** @var ?LoggerInterface */
9395
private $logger;
9496

9597
public function __construct($parameters) {
@@ -237,7 +239,7 @@ public function copy($path1, $path2) {
237239
$target = $this->fopen($path2, 'w');
238240
[, $result] = \OC_Helper::streamCopy($source, $target);
239241
if (!$result) {
240-
\OC::$server->getLogger()->warning("Failed to write data while copying $path1 to $path2");
242+
\OC::$server->get(LoggerInterface::class)->warning("Failed to write data while copying $path1 to $path2");
241243
}
242244
$this->removeCachedFile($path2);
243245
return $result;
@@ -459,11 +461,13 @@ public function test() {
459461
if ($this->stat('')) {
460462
return true;
461463
}
462-
\OC::$server->getLogger()->info("External storage not available: stat() failed");
464+
\OC::$server->get(LoggerInterface::class)->info("External storage not available: stat() failed");
463465
return false;
464466
} catch (\Exception $e) {
465-
\OC::$server->getLogger()->warning("External storage not available: " . $e->getMessage());
466-
\OC::$server->getLogger()->logException($e, ['level' => ILogger::WARN]);
467+
\OC::$server->get(LoggerInterface::class)->warning(
468+
"External storage not available: " . $e->getMessage(),
469+
['exception' => $e]
470+
);
467471
return false;
468472
}
469473
}
@@ -628,7 +632,7 @@ public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $t
628632
$this->writeStream($targetInternalPath, $source);
629633
$result = true;
630634
} catch (\Exception $e) {
631-
\OC::$server->getLogger()->logException($e, ['level' => ILogger::WARN, 'message' => 'Failed to copy stream to storage']);
635+
\OC::$server->get(LoggerInterface::class)->warning('Failed to copy stream to storage', ['exception' => $e]);
632636
}
633637
}
634638

@@ -758,7 +762,7 @@ public function acquireLock($path, $type, ILockingProvider $provider) {
758762
$provider->acquireLock('files/' . md5($this->getId() . '::' . trim($path, '/')), $type, $this->getId() . '::' . $path);
759763
} catch (LockedException $e) {
760764
if ($logger) {
761-
$logger->logException($e, ['level' => ILogger::INFO]);
765+
$logger->info($e->getMessage(), ['exception' => $e]);
762766
}
763767
throw $e;
764768
}
@@ -790,7 +794,7 @@ public function releaseLock($path, $type, ILockingProvider $provider) {
790794
$provider->releaseLock('files/' . md5($this->getId() . '::' . trim($path, '/')), $type);
791795
} catch (LockedException $e) {
792796
if ($logger) {
793-
$logger->logException($e, ['level' => ILogger::INFO]);
797+
$logger->info($e->getMessage(), ['exception' => $e]);
794798
}
795799
throw $e;
796800
}
@@ -821,15 +825,17 @@ public function changeLock($path, $type, ILockingProvider $provider) {
821825
try {
822826
$provider->changeLock('files/' . md5($this->getId() . '::' . trim($path, '/')), $type);
823827
} catch (LockedException $e) {
824-
\OC::$server->getLogger()->logException($e, ['level' => ILogger::INFO]);
828+
if ($logger) {
829+
$logger->info($e->getMessage(), ['exception' => $e]);
830+
}
825831
throw $e;
826832
}
827833
}
828834

829-
private function getLockLogger() {
835+
private function getLockLogger(): ?LoggerInterface {
830836
if (is_null($this->shouldLogLocks)) {
831837
$this->shouldLogLocks = \OC::$server->getConfig()->getSystemValue('filelocking.debug', false);
832-
$this->logger = $this->shouldLogLocks ? \OC::$server->getLogger() : null;
838+
$this->logger = $this->shouldLogLocks ? \OC::$server->get(LoggerInterface::class) : null;
833839
}
834840
return $this->logger;
835841
}

0 commit comments

Comments
 (0)