Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Migrate more classes of lib/private to LoggerInterface
Signed-off-by: Côme Chilliet <[email protected]>
  • Loading branch information
come-nc committed Apr 26, 2022
commit 069477e608566c6ea9edbe259b46c591a82bd8af
17 changes: 8 additions & 9 deletions lib/private/Files/Cache/Scanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@
namespace OC\Files\Cache;

use Doctrine\DBAL\Exception;
use OC\Files\Storage\Wrapper\Jail;
use OC\Files\Storage\Wrapper\Encoding;
use OC\Hooks\BasicEmitter;
use OCP\Files\Cache\IScanner;
use OCP\Files\ForbiddenException;
use OCP\Files\Storage\IReliableEtagStorage;
use OCP\ILogger;
use OCP\Lock\ILockingProvider;
use OC\Files\Storage\Wrapper\Encoding;
use OC\Files\Storage\Wrapper\Jail;
use OC\Hooks\BasicEmitter;
use Psr\Log\LoggerInterface;

/**
* Class Scanner
Expand Down Expand Up @@ -115,7 +115,7 @@ public function setUseTransactions($useTransactions) {
protected function getData($path) {
$data = $this->storage->getMetaData($path);
if (is_null($data)) {
\OCP\Util::writeLog(Scanner::class, "!!! Path '$path' is not accessible or present !!!", ILogger::DEBUG);
\OC::$server->get(LoggerInterface::class)->debug("!!! Path '$path' is not accessible or present !!!", ['app' => 'core']);
}
return $data;
}
Expand Down Expand Up @@ -425,7 +425,7 @@ private function handleChildren($path, $recursive, $reuse, $folderId, $lock, &$s
$file = trim(\OC\Files\Filesystem::normalizePath($originalFile), '/');
if (trim($originalFile, '/') !== $file) {
// encoding mismatch, might require compatibility wrapper
\OC::$server->getLogger()->debug('Scanner: Skipping non-normalized file name "'. $originalFile . '" in path "' . $path . '".', ['app' => 'core']);
\OC::$server->get(LoggerInterface::class)->debug('Scanner: Skipping non-normalized file name "'. $originalFile . '" in path "' . $path . '".', ['app' => 'core']);
$this->emit('\OC\Files\Cache\Scanner', 'normalizedNameMismatch', [$path ? $path . '/' . $originalFile : $originalFile]);
// skip this entry
continue;
Expand Down Expand Up @@ -456,10 +456,9 @@ private function handleChildren($path, $recursive, $reuse, $folderId, $lock, &$s
\OC::$server->getDatabaseConnection()->rollback();
\OC::$server->getDatabaseConnection()->beginTransaction();
}
\OC::$server->getLogger()->logException($ex, [
'message' => 'Exception while scanning file "' . $child . '"',
'level' => ILogger::DEBUG,
\OC::$server->get(LoggerInterface::class)->debug('Exception while scanning file "' . $child . '"', [
'app' => 'core',
'exception' => $ex,
]);
$exceptionOccurred = true;
} catch (\OCP\Lock\LockedException $e) {
Expand Down
6 changes: 3 additions & 3 deletions lib/private/Files/Mount/MountPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
use OC\Files\Storage\StorageFactory;
use OCP\Files\Mount\IMountPoint;
use OCP\Files\Storage\IStorageFactory;
use OCP\ILogger;
use Psr\Log\LoggerInterface;

class MountPoint implements IMountPoint {
/**
Expand Down Expand Up @@ -173,12 +173,12 @@ private function createStorage() {
// the root storage could not be initialized, show the user!
throw new \Exception('The root storage could not be initialized. Please contact your local administrator.', $exception->getCode(), $exception);
} else {
\OC::$server->getLogger()->logException($exception, ['level' => ILogger::ERROR]);
\OC::$server->get(LoggerInterface::class)->error($exception->getMessage(), ['exception' => $exception]);
}
return;
}
} else {
\OCP\Util::writeLog('core', 'storage backend ' . $this->class . ' not found', ILogger::ERROR);
\OC::$server->get(LoggerInterface::class)->error('Storage backend ' . $this->class . ' not found', ['app' => 'core']);
$this->invalidStorage = true;
return;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/private/Files/Mount/ObjectHomeMountProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
use OCP\Files\Config\IHomeMountProvider;
use OCP\Files\Storage\IStorageFactory;
use OCP\IConfig;
use OCP\ILogger;
use OCP\IUser;
use Psr\Log\LoggerInterface;

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

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

// sanity checks
if (empty($config['class'])) {
\OCP\Util::writeLog('files', 'No class given for objectstore', ILogger::ERROR);
\OC::$server->get(LoggerInterface::class)->error('No class given for objectstore', ['app' => 'files']);
}
if (!isset($config['arguments'])) {
$config['arguments'] = [];
Expand Down
11 changes: 5 additions & 6 deletions lib/private/Files/ObjectStore/S3ConnectionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
use GuzzleHttp\Promise;
use GuzzleHttp\Promise\RejectedPromise;
use OCP\ICertificateManager;
use OCP\ILogger;
use Psr\Log\LoggerInterface;

trait S3ConnectionTrait {
/** @var array */
Expand Down Expand Up @@ -150,13 +150,13 @@ public function getConnection() {
$this->connection = new S3Client($options);

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

if ($this->params['verify_bucket_exists'] && !$this->connection->doesBucketExist($this->bucket)) {
$logger = \OC::$server->getLogger();
$logger = \OC::$server->get(LoggerInterface::class);
try {
$logger->info('Bucket "' . $this->bucket . '" does not exist - creating it.', ['app' => 'objectstore']);
if (!$this->connection::isBucketDnsCompatible($this->bucket)) {
Expand All @@ -165,9 +165,8 @@ public function getConnection() {
$this->connection->createBucket(['Bucket' => $this->bucket]);
$this->testTimeout();
} catch (S3Exception $e) {
$logger->logException($e, [
'message' => 'Invalid remote storage.',
'level' => ILogger::DEBUG,
$logger->debug('Invalid remote storage.', [
'exception' => $e,
'app' => 'objectstore',
]);
throw new \Exception('Creation of bucket "' . $this->bucket . '" failed. ' . $e->getMessage());
Expand Down
30 changes: 14 additions & 16 deletions lib/private/Files/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@
use OCP\Files\NotFoundException;
use OCP\Files\ReservedWordException;
use OCP\Files\Storage\IStorage;
use OCP\ILogger;
use OCP\IUser;
use OCP\Lock\ILockingProvider;
use OCP\Lock\LockedException;
use Psr\Log\LoggerInterface;

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

/** @var \OCP\ILogger */
private $logger;
private LoggerInterface $logger;

private DisplayNameCache $displayNameCache;

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

public function getAbsolutePath($path = '/') {
Expand Down Expand Up @@ -579,7 +578,7 @@ public function touch($path, $mtime = null) {
try {
$result = $this->basicOperation('touch', $path, $hooks, $mtime);
} catch (\Exception $e) {
$this->logger->logException($e, ['level' => ILogger::INFO, 'message' => 'Error while setting modified time']);
$this->logger->info('Error while setting modified time', ['app' => 'core', 'exception' => $e]);
$result = false;
}
if (!$result) {
Expand Down Expand Up @@ -1000,11 +999,11 @@ public function fopen($path, $mode) {
$hooks[] = 'write';
break;
default:
\OCP\Util::writeLog('core', 'invalid mode (' . $mode . ') for ' . $path, ILogger::ERROR);
$this->logger->error('invalid mode (' . $mode . ') for ' . $path, ['app' => 'core']);
}

if ($mode !== 'r' && $mode !== 'w') {
\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');
$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']);
}

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

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

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

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

Expand Down Expand Up @@ -2146,9 +2144,9 @@ public function getPathRelativeToFiles($absolutePath) {
// "$user", "files", "path/to/dir"
if (!isset($parts[1]) || $parts[1] !== 'files') {
$this->logger->error(
'$absolutePath must be relative to "files", value is "%s"',
'$absolutePath must be relative to "files", value is "{absolutePath}"',
[
$absolutePath
'absolutePath' => $absolutePath,
]
);
throw new \InvalidArgumentException('$absolutePath must be relative to "files"');
Expand Down
3 changes: 1 addition & 2 deletions lib/private/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
use OCP\HintException;
use OCP\Http\Client\IClientService;
use OCP\IConfig;
use OCP\ILogger;
use OCP\ITempManager;
use phpseclib\File\X509;
use Psr\Log\LoggerInterface;
Expand Down Expand Up @@ -501,7 +500,7 @@ public function removeApp($appId) {
OC_Helper::rmdirr($appDir);
return true;
} else {
\OCP\Util::writeLog('core', 'can\'t remove app '.$appId.'. It is not installed.', ILogger::ERROR);
$this->logger->error('can\'t remove app '.$appId.'. It is not installed.');

return false;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/private/NaturalSort.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*/
namespace OC;

use OCP\ILogger;
use Psr\Log\LoggerInterface;

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

Expand Down
6 changes: 3 additions & 3 deletions lib/private/Preview/Office.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
use OCP\Files\File;
use OCP\Files\FileInfo;
use OCP\IImage;
use OCP\ILogger;
use Psr\Log\LoggerInterface;

abstract class Office extends ProviderV2 {
/**
Expand Down Expand Up @@ -76,8 +76,8 @@ public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage {
} catch (\Exception $e) {
$this->cleanTmpFiles();
unlink($pngPreview);
\OC::$server->getLogger()->logException($e, [
'level' => ILogger::ERROR,
\OC::$server->get(LoggerInterface::class)->error($e->getMessage(), [
'exception' => $e,
'app' => 'core',
]);
return null;
Expand Down
6 changes: 3 additions & 3 deletions lib/private/Preview/SVG.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

use OCP\Files\File;
use OCP\IImage;
use OCP\ILogger;
use Psr\Log\LoggerInterface;

class SVG extends ProviderV2 {
/**
Expand Down Expand Up @@ -60,8 +60,8 @@ public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage {
$svg->readImageBlob($content);
$svg->setImageFormat('png32');
} catch (\Exception $e) {
\OC::$server->getLogger()->logException($e, [
'level' => ILogger::ERROR,
\OC::$server->get(LoggerInterface::class)->error($e->getMessage(), [
'exception' => $e,
'app' => 'core',
]);
return null;
Expand Down
22 changes: 12 additions & 10 deletions lib/private/Share/Share.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
namespace OC\Share;

use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\ILogger;
use OCP\Share\IShare;
use Psr\Log\LoggerInterface;

/**
* This class provides the ability for apps to share their content between users.
Expand Down Expand Up @@ -80,10 +80,10 @@ public static function registerBackend($itemType, $class, $collectionOf = null,
];
return true;
}
\OCP\Util::writeLog('OCP\Share',
\OC::$server->get(LoggerInterface::class)->warning(
'Sharing backend '.$class.' not registered, '.self::$backendTypes[$itemType]['class']
.' is already registered for '.$itemType,
ILogger::WARN);
['app' => 'OCP\Share']);
}
return false;
}
Expand Down Expand Up @@ -256,6 +256,7 @@ public static function getItemShared($itemType, $itemSource, $format = self::FOR
*/
public static function getBackend($itemType) {
$l = \OC::$server->getL10N('lib');
$logger = \OC::$server->get(LoggerInterface::class);
if (isset(self::$backends[$itemType])) {
return self::$backends[$itemType];
} elseif (isset(self::$backendTypes[$itemType]['class'])) {
Expand All @@ -265,20 +266,20 @@ public static function getBackend($itemType) {
if (!(self::$backends[$itemType] instanceof \OCP\Share_Backend)) {
$message = 'Sharing backend %s must implement the interface OCP\Share_Backend';
$message_t = $l->t('Sharing backend %s must implement the interface OCP\Share_Backend', [$class]);
\OCP\Util::writeLog('OCP\Share', sprintf($message, $class), ILogger::ERROR);
$logger->error(sprintf($message, $class), ['app' => 'OCP\Share']);
throw new \Exception($message_t);
}
return self::$backends[$itemType];
} else {
$message = 'Sharing backend %s not found';
$message_t = $l->t('Sharing backend %s not found', [$class]);
\OCP\Util::writeLog('OCP\Share', sprintf($message, $class), ILogger::ERROR);
$logger->error(sprintf($message, $class), ['app' => 'OCP\Share']);
throw new \Exception($message_t);
}
}
$message = 'Sharing backend for %s not found';
$message_t = $l->t('Sharing backend for %s not found', [$itemType]);
\OCP\Util::writeLog('OCP\Share', sprintf($message, $itemType), ILogger::ERROR);
$logger->error(sprintf($message, $itemType), ['app' => 'OCP\Share']);
throw new \Exception($message_t);
}

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

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