Skip to content

Commit 069477e

Browse files
committed
Migrate more classes of lib/private to LoggerInterface
Signed-off-by: Côme Chilliet <[email protected]>
1 parent 0654b24 commit 069477e

File tree

11 files changed

+59
-67
lines changed

11 files changed

+59
-67
lines changed

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/View.php

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@
6464
use OCP\Files\NotFoundException;
6565
use OCP\Files\ReservedWordException;
6666
use OCP\Files\Storage\IStorage;
67-
use OCP\ILogger;
6867
use OCP\IUser;
6968
use OCP\Lock\ILockingProvider;
7069
use OCP\Lock\LockedException;
70+
use Psr\Log\LoggerInterface;
7171

7272
/**
7373
* Class to provide access to ownCloud filesystem via a "view", and methods for
@@ -101,8 +101,7 @@ class View {
101101
/** @var \OC\User\Manager */
102102
private $userManager;
103103

104-
/** @var \OCP\ILogger */
105-
private $logger;
104+
private LoggerInterface $logger;
106105

107106
private DisplayNameCache $displayNameCache;
108107

@@ -123,7 +122,7 @@ public function __construct($root = '') {
123122
$this->lockingEnabled = !($this->lockingProvider instanceof \OC\Lock\NoopLockingProvider);
124123
$this->userManager = \OC::$server->getUserManager();
125124
$this->displayNameCache = \OC::$server->get(DisplayNameCache::class);
126-
$this->logger = \OC::$server->getLogger();
125+
$this->logger = \OC::$server->get(LoggerInterface::class);
127126
}
128127

129128
public function getAbsolutePath($path = '/') {
@@ -579,7 +578,7 @@ public function touch($path, $mtime = null) {
579578
try {
580579
$result = $this->basicOperation('touch', $path, $hooks, $mtime);
581580
} catch (\Exception $e) {
582-
$this->logger->logException($e, ['level' => ILogger::INFO, 'message' => 'Error while setting modified time']);
581+
$this->logger->info('Error while setting modified time', ['app' => 'core', 'exception' => $e]);
583582
$result = false;
584583
}
585584
if (!$result) {
@@ -1000,11 +999,11 @@ public function fopen($path, $mode) {
1000999
$hooks[] = 'write';
10011000
break;
10021001
default:
1003-
\OCP\Util::writeLog('core', 'invalid mode (' . $mode . ') for ' . $path, ILogger::ERROR);
1002+
$this->logger->error('invalid mode (' . $mode . ') for ' . $path, ['app' => 'core']);
10041003
}
10051004

10061005
if ($mode !== 'r' && $mode !== 'w') {
1007-
\OC::$server->getLogger()->info('Trying to open a file with a mode other than "r" or "w" can cause severe performance issues with some backends');
1006+
$this->logger->info('Trying to open a file with a mode other than "r" or "w" can cause severe performance issues with some backends', ['app' => 'core']);
10081007
}
10091008

10101009
return $this->basicOperation('fopen', $path, $hooks, $mode);
@@ -1418,7 +1417,7 @@ public function getFileInfo($path, $includeMountPoints = true) {
14181417

14191418
return $info;
14201419
} else {
1421-
\OC::$server->getLogger()->warning('Storage not valid for mountpoint: ' . $mount->getMountPoint());
1420+
$this->logger->warning('Storage not valid for mountpoint: ' . $mount->getMountPoint(), ['app' => 'core']);
14221421
}
14231422

14241423
return false;
@@ -1502,10 +1501,9 @@ public function getDirectoryContent($directory, $mimetype_filter = '', \OCP\File
15021501
continue;
15031502
} catch (\Exception $e) {
15041503
// sometimes when the storage is not available it can be any exception
1505-
\OC::$server->getLogger()->logException($e, [
1506-
'message' => 'Exception while scanning storage "' . $subStorage->getId() . '"',
1507-
'level' => ILogger::ERROR,
1508-
'app' => 'lib',
1504+
$this->logger->error('Exception while scanning storage "' . $subStorage->getId() . '"', [
1505+
'exception' => $e,
1506+
'app' => 'core',
15091507
]);
15101508
continue;
15111509
}
@@ -1816,9 +1814,9 @@ private function targetIsNotShared(IStorage $targetStorage, string $targetIntern
18161814
);
18171815

18181816
if (count($shares) > 0) {
1819-
\OCP\Util::writeLog('files',
1817+
$this->logger->debug(
18201818
'It is not allowed to move one mount point into a shared folder',
1821-
ILogger::DEBUG);
1819+
['app' => 'files']);
18221820
return false;
18231821
}
18241822

@@ -2146,9 +2144,9 @@ public function getPathRelativeToFiles($absolutePath) {
21462144
// "$user", "files", "path/to/dir"
21472145
if (!isset($parts[1]) || $parts[1] !== 'files') {
21482146
$this->logger->error(
2149-
'$absolutePath must be relative to "files", value is "%s"',
2147+
'$absolutePath must be relative to "files", value is "{absolutePath}"',
21502148
[
2151-
$absolutePath
2149+
'absolutePath' => $absolutePath,
21522150
]
21532151
);
21542152
throw new \InvalidArgumentException('$absolutePath must be relative to "files"');

lib/private/Installer.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
use OCP\HintException;
5252
use OCP\Http\Client\IClientService;
5353
use OCP\IConfig;
54-
use OCP\ILogger;
5554
use OCP\ITempManager;
5655
use phpseclib\File\X509;
5756
use Psr\Log\LoggerInterface;
@@ -501,7 +500,7 @@ public function removeApp($appId) {
501500
OC_Helper::rmdirr($appDir);
502501
return true;
503502
} else {
504-
\OCP\Util::writeLog('core', 'can\'t remove app '.$appId.'. It is not installed.', ILogger::ERROR);
503+
$this->logger->error('can\'t remove app '.$appId.'. It is not installed.');
505504

506505
return false;
507506
}

lib/private/NaturalSort.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*/
2727
namespace OC;
2828

29-
use OCP\ILogger;
29+
use Psr\Log\LoggerInterface;
3030

3131
class NaturalSort {
3232
private static $instance;
@@ -42,7 +42,7 @@ public function __construct($injectedCollator = null) {
4242
// or inject an instance of \OC\NaturalSort_DefaultCollator to force using Owncloud's default collator
4343
if (isset($injectedCollator)) {
4444
$this->collator = $injectedCollator;
45-
\OCP\Util::writeLog('core', 'forced use of '.get_class($injectedCollator), ILogger::DEBUG);
45+
\OC::$server->get(LoggerInterface::class)->debug('forced use of '.get_class($injectedCollator));
4646
}
4747
}
4848

lib/private/Preview/Office.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
use OCP\Files\File;
3232
use OCP\Files\FileInfo;
3333
use OCP\IImage;
34-
use OCP\ILogger;
34+
use Psr\Log\LoggerInterface;
3535

3636
abstract class Office extends ProviderV2 {
3737
/**
@@ -76,8 +76,8 @@ public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage {
7676
} catch (\Exception $e) {
7777
$this->cleanTmpFiles();
7878
unlink($pngPreview);
79-
\OC::$server->getLogger()->logException($e, [
80-
'level' => ILogger::ERROR,
79+
\OC::$server->get(LoggerInterface::class)->error($e->getMessage(), [
80+
'exception' => $e,
8181
'app' => 'core',
8282
]);
8383
return null;

lib/private/Preview/SVG.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
use OCP\Files\File;
3131
use OCP\IImage;
32-
use OCP\ILogger;
32+
use Psr\Log\LoggerInterface;
3333

3434
class SVG extends ProviderV2 {
3535
/**
@@ -60,8 +60,8 @@ public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage {
6060
$svg->readImageBlob($content);
6161
$svg->setImageFormat('png32');
6262
} catch (\Exception $e) {
63-
\OC::$server->getLogger()->logException($e, [
64-
'level' => ILogger::ERROR,
63+
\OC::$server->get(LoggerInterface::class)->error($e->getMessage(), [
64+
'exception' => $e,
6565
'app' => 'core',
6666
]);
6767
return null;

lib/private/Share/Share.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
namespace OC\Share;
3636

3737
use OCP\DB\QueryBuilder\IQueryBuilder;
38-
use OCP\ILogger;
3938
use OCP\Share\IShare;
39+
use Psr\Log\LoggerInterface;
4040

4141
/**
4242
* This class provides the ability for apps to share their content between users.
@@ -80,10 +80,10 @@ public static function registerBackend($itemType, $class, $collectionOf = null,
8080
];
8181
return true;
8282
}
83-
\OCP\Util::writeLog('OCP\Share',
83+
\OC::$server->get(LoggerInterface::class)->warning(
8484
'Sharing backend '.$class.' not registered, '.self::$backendTypes[$itemType]['class']
8585
.' is already registered for '.$itemType,
86-
ILogger::WARN);
86+
['app' => 'OCP\Share']);
8787
}
8888
return false;
8989
}
@@ -256,6 +256,7 @@ public static function getItemShared($itemType, $itemSource, $format = self::FOR
256256
*/
257257
public static function getBackend($itemType) {
258258
$l = \OC::$server->getL10N('lib');
259+
$logger = \OC::$server->get(LoggerInterface::class);
259260
if (isset(self::$backends[$itemType])) {
260261
return self::$backends[$itemType];
261262
} elseif (isset(self::$backendTypes[$itemType]['class'])) {
@@ -265,20 +266,20 @@ public static function getBackend($itemType) {
265266
if (!(self::$backends[$itemType] instanceof \OCP\Share_Backend)) {
266267
$message = 'Sharing backend %s must implement the interface OCP\Share_Backend';
267268
$message_t = $l->t('Sharing backend %s must implement the interface OCP\Share_Backend', [$class]);
268-
\OCP\Util::writeLog('OCP\Share', sprintf($message, $class), ILogger::ERROR);
269+
$logger->error(sprintf($message, $class), ['app' => 'OCP\Share']);
269270
throw new \Exception($message_t);
270271
}
271272
return self::$backends[$itemType];
272273
} else {
273274
$message = 'Sharing backend %s not found';
274275
$message_t = $l->t('Sharing backend %s not found', [$class]);
275-
\OCP\Util::writeLog('OCP\Share', sprintf($message, $class), ILogger::ERROR);
276+
$logger->error(sprintf($message, $class), ['app' => 'OCP\Share']);
276277
throw new \Exception($message_t);
277278
}
278279
}
279280
$message = 'Sharing backend for %s not found';
280281
$message_t = $l->t('Sharing backend for %s not found', [$itemType]);
281-
\OCP\Util::writeLog('OCP\Share', sprintf($message, $itemType), ILogger::ERROR);
282+
$logger->error(sprintf($message, $itemType), ['app' => 'OCP\Share']);
282283
throw new \Exception($message_t);
283284
}
284285

@@ -482,9 +483,9 @@ public static function getItems($itemType, $item = null, $shareType = null, $sha
482483
$query = \OC_DB::prepare('SELECT '.$select.' FROM `*PREFIX*share` '.$where, $queryLimit);
483484
$result = $query->execute($queryArgs);
484485
if ($result === false) {
485-
\OCP\Util::writeLog('OCP\Share',
486+
\OC::$server->get(LoggerInterface::class)->error(
486487
\OC_DB::getErrorMessage() . ', select=' . $select . ' where=',
487-
ILogger::ERROR);
488+
['app' => 'OCP\Share']);
488489
}
489490
$items = [];
490491
$targets = [];
@@ -552,9 +553,10 @@ public static function getItems($itemType, $item = null, $shareType = null, $sha
552553
$parentResult->closeCursor();
553554

554555
if ($parentRow === false) {
555-
\OCP\Util::writeLog('OCP\Share', 'Can\'t select parent: ' .
556+
\OC::$server->get(LoggerInterface::class)->error(
557+
'Can\'t select parent: ' .
556558
\OC_DB::getErrorMessage() . ', select=' . $select . ' where=' . $where,
557-
ILogger::ERROR);
559+
['app' => 'OCP\Share']);
558560
} else {
559561
$tmpPath = $parentRow['file_target'];
560562
// find the right position where the row path continues from the target path

0 commit comments

Comments
 (0)