Skip to content

Commit 23f7a37

Browse files
committed
Remove ILogger usages in lib/private/Files/Storage
Signed-off-by: Côme Chilliet <[email protected]>
1 parent 069477e commit 23f7a37

File tree

3 files changed

+25
-19
lines changed

3 files changed

+25
-19
lines changed

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
}

lib/private/Files/Storage/DAV.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@
5050
use OCP\Files\StorageNotAvailableException;
5151
use OCP\Http\Client\IClientService;
5252
use OCP\ICertificateManager;
53-
use OCP\ILogger;
5453
use OCP\Util;
5554
use Psr\Http\Message\ResponseInterface;
5655
use Sabre\DAV\Client;
5756
use Sabre\DAV\Xml\Property\ResourceType;
5857
use Sabre\HTTP\ClientException;
5958
use Sabre\HTTP\ClientHttpException;
59+
use Psr\Log\LoggerInterface;
6060

6161
/**
6262
* Class DAV
@@ -370,7 +370,7 @@ public function fopen($path, $mode) {
370370
if ($response->getStatusCode() === Http::STATUS_LOCKED) {
371371
throw new \OCP\Lock\LockedException($path);
372372
} else {
373-
Util::writeLog("webdav client", 'Guzzle get returned status code ' . $response->getStatusCode(), ILogger::ERROR);
373+
\OC::$server->get(LoggerInterface::class)->error('Guzzle get returned status code ' . $response->getStatusCode(), ['app' => 'webdav client']);
374374
}
375375
}
376376

@@ -843,7 +843,7 @@ public function hasUpdated($path, $time) {
843843
* @throws ForbiddenException if the action is not allowed
844844
*/
845845
protected function convertException(Exception $e, $path = '') {
846-
\OC::$server->getLogger()->logException($e, ['app' => 'files_external', 'level' => ILogger::DEBUG]);
846+
\OC::$server->get(LoggerInterface::class)->debug($e->getMessage(), ['app' => 'files_external', 'exception' => $e]);
847847
if ($e instanceof ClientHttpException) {
848848
if ($e->getHttpStatus() === Http::STATUS_LOCKED) {
849849
throw new \OCP\Lock\LockedException($path);

lib/private/Files/Storage/Local.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
use OCP\Files\IMimeTypeDetector;
5151
use OCP\Files\Storage\IStorage;
5252
use OCP\IConfig;
53-
use OCP\ILogger;
53+
use Psr\Log\LoggerInterface;
5454

5555
/**
5656
* for local filestore, we only have to map the paths
@@ -323,17 +323,17 @@ public function rename($path1, $path2) {
323323
$dstParent = dirname($path2);
324324

325325
if (!$this->isUpdatable($srcParent)) {
326-
\OCP\Util::writeLog('core', 'unable to rename, source directory is not writable : ' . $srcParent, ILogger::ERROR);
326+
\OC::$server->get(LoggerInterface::class)->error('unable to rename, source directory is not writable : ' . $srcParent, ['app' => 'core']);
327327
return false;
328328
}
329329

330330
if (!$this->isUpdatable($dstParent)) {
331-
\OCP\Util::writeLog('core', 'unable to rename, destination directory is not writable : ' . $dstParent, ILogger::ERROR);
331+
\OC::$server->get(LoggerInterface::class)->error('unable to rename, destination directory is not writable : ' . $dstParent, ['app' => 'core']);
332332
return false;
333333
}
334334

335335
if (!$this->file_exists($path1)) {
336-
\OCP\Util::writeLog('core', 'unable to rename, file does not exists : ' . $path1, ILogger::ERROR);
336+
\OC::$server->get(LoggerInterface::class)->error('unable to rename, file does not exists : ' . $path1, ['app' => 'core']);
337337
return false;
338338
}
339339

@@ -484,7 +484,7 @@ public function getSourcePath($path) {
484484
return $fullPath;
485485
}
486486

487-
\OCP\Util::writeLog('core', "Following symlinks is not allowed ('$fullPath' -> '$realPath' not inside '{$this->realDataDir}')", ILogger::ERROR);
487+
\OC::$server->get(LoggerInterface::class)->error("Following symlinks is not allowed ('$fullPath' -> '$realPath' not inside '{$this->realDataDir}')", ['app' => 'core']);
488488
throw new ForbiddenException('Following symlinks is not allowed', false);
489489
}
490490

0 commit comments

Comments
 (0)