use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IL10N;
-use OCP\ILogger;
use OCP\IRequest;
use OCP\IUserSession;
+use Psr\Log\LoggerInterface;
/**
* Global storages controller
* @param IRequest $request request object
* @param IL10N $l10n l10n service
* @param GlobalStoragesService $globalStoragesService storage service
- * @param ILogger $logger
+ * @param LoggerInterface $logger
* @param IUserSession $userSession
* @param IGroupManager $groupManager
* @param IConfig $config
IRequest $request,
IL10N $l10n,
GlobalStoragesService $globalStoragesService,
- ILogger $logger,
+ LoggerInterface $logger,
IUserSession $userSession,
IGroupManager $groupManager,
IConfig $config
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IL10N;
-use OCP\ILogger;
use OCP\IRequest;
use OCP\IUserSession;
+use Psr\Log\LoggerInterface;
/**
* Base class for storages controllers
*/
abstract class StoragesController extends Controller {
-
- /**
- * L10N service
- *
- * @var IL10N
- */
- protected $l10n;
-
- /**
- * Storages service
- *
- * @var StoragesService
- */
- protected $service;
-
- /**
- * @var ILogger
- */
- protected $logger;
-
- /**
- * @var IUserSession
- */
- protected $userSession;
-
- /**
- * @var IGroupManager
- */
- protected $groupManager;
-
- /**
- * @var IConfig
- */
- protected $config;
-
/**
* Creates a new storages controller.
*
* @param IRequest $request request object
* @param IL10N $l10n l10n service
* @param StoragesService $storagesService storage service
- * @param ILogger $logger
+ * @param LoggerInterface $logger
*/
public function __construct(
$AppName,
IRequest $request,
- IL10N $l10n,
- StoragesService $storagesService,
- ILogger $logger,
- IUserSession $userSession,
- IGroupManager $groupManager,
- IConfig $config
+ protected IL10N $l10n,
+ protected StoragesService $service,
+ protected LoggerInterface $logger,
+ protected IUserSession $userSession,
+ protected IGroupManager $groupManager,
+ protected IConfig $config
) {
parent::__construct($AppName, $request);
- $this->l10n = $l10n;
- $this->service = $storagesService;
- $this->logger = $logger;
- $this->userSession = $userSession;
- $this->groupManager = $groupManager;
- $this->config = $config;
}
/**
$priority
);
} catch (\InvalidArgumentException $e) {
- $this->logger->logException($e);
+ $this->logger->error($e->getMessage(), ['exception' => $e]);
return new DataResponse(
[
'message' => $this->l10n->t('Invalid backend or authentication mechanism class')
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IL10N;
-use OCP\ILogger;
use OCP\IRequest;
use OCP\IUserSession;
+use Psr\Log\LoggerInterface;
/**
* User global storages controller
* @param IRequest $request request object
* @param IL10N $l10n l10n service
* @param UserGlobalStoragesService $userGlobalStoragesService storage service
- * @param ILogger $logger
+ * @param LoggerInterface $logger
* @param IUserSession $userSession
* @param IGroupManager $groupManager
*/
IRequest $request,
IL10N $l10n,
UserGlobalStoragesService $userGlobalStoragesService,
- ILogger $logger,
+ LoggerInterface $logger,
IUserSession $userSession,
IGroupManager $groupManager,
IConfig $config
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IL10N;
-use OCP\ILogger;
use OCP\IRequest;
use OCP\IUserSession;
+use Psr\Log\LoggerInterface;
/**
* User storages controller
* @param IRequest $request request object
* @param IL10N $l10n l10n service
* @param UserStoragesService $userStoragesService storage service
- * @param ILogger $logger
+ * @param LoggerInterface $logger
* @param IUserSession $userSession
* @param IGroupManager $groupManager
*/
IRequest $request,
IL10N $l10n,
UserStoragesService $userStoragesService,
- ILogger $logger,
+ LoggerInterface $logger,
IUserSession $userSession,
IGroupManager $groupManager,
IConfig $config
use OCP\Constants;
use OCP\Files\FileInfo;
use OCP\Files\StorageNotAvailableException;
+use Psr\Log\LoggerInterface;
class FTP extends Common {
use CopyDirectory;
if ($this->is_dir($path)) {
$list = $this->getConnection()->mlsd($this->buildPath($path));
if (!$list) {
- \OC::$server->getLogger()->warning("Unable to get last modified date for ftp folder ($path), failed to list folder contents");
+ \OC::$server->get(LoggerInterface::class)->warning("Unable to get last modified date for ftp folder ($path), failed to list folder contents");
return time();
}
$currentDir = current(array_filter($list, function ($item) {
}
return $time->getTimestamp();
} else {
- \OC::$server->getLogger()->warning("Unable to get last modified date for ftp folder ($path), folder contents doesn't include current folder");
+ \OC::$server->get(LoggerInterface::class)->warning("Unable to get last modified date for ftp folder ($path), folder contents doesn't include current folder");
return time();
}
} else {
use Icewind\SMB\System;
use Icewind\Streams\CallbackWrapper;
use Icewind\Streams\IteratorDirectory;
-use OCP\Cache\CappedMemoryCache;
use OC\Files\Filesystem;
use OC\Files\Storage\Common;
use OCA\Files_External\Lib\Notify\SMBNotifyHandler;
+use OCP\Cache\CappedMemoryCache;
use OCP\Constants;
use OCP\Files\EntityTooLargeException;
use OCP\Files\Notify\IChange;
use OCP\Files\Storage\INotifyStorage;
use OCP\Files\StorageAuthException;
use OCP\Files\StorageNotAvailableException;
-use OCP\ILogger;
+use Psr\Log\LoggerInterface;
class SMB extends Common implements INotifyStorage {
/**
/** @var CappedMemoryCache<IFileInfo> */
protected CappedMemoryCache $statCache;
- /** @var ILogger */
+ /** @var LoggerInterface */
protected $logger;
/** @var bool */
}
if (isset($params['logger'])) {
+ if (!$params['logger'] instanceof LoggerInterface) {
+ throw new \Exception(
+ 'Invalid logger. Got '
+ . get_class($params['logger'])
+ . ' Expected ' . LoggerInterface::class
+ );
+ }
$this->logger = $params['logger'];
} else {
- $this->logger = \OC::$server->getLogger();
+ $this->logger = \OC::$server->get(LoggerInterface::class);
}
$options = new Options();
* @throws StorageAuthException
*/
protected function throwUnavailable(\Exception $e) {
- $this->logger->logException($e, ['message' => 'Error while getting file info']);
+ $this->logger->error('Error while getting file info', ['exception' => $e]);
throw new StorageAuthException($e->getMessage(), $e);
}
yield $file;
}
} catch (ForbiddenException $e) {
- $this->logger->logException($e, ['level' => ILogger::DEBUG, 'message' => 'Hiding forbidden entry ' . $file->getName()]);
+ $this->logger->debug($e->getMessage(), ['exception' => $e]);
} catch (NotFoundException $e) {
- $this->logger->logException($e, ['level' => ILogger::DEBUG, 'message' => 'Hiding not found entry ' . $file->getName()]);
+ $this->logger->debug('Hiding forbidden entry ' . $file->getName(), ['exception' => $e]);
}
}
} catch (ConnectException $e) {
- $this->logger->logException($e, ['message' => 'Error while getting folder content']);
+ $this->logger->error('Error while getting folder content', ['exception' => $e]);
throw new StorageNotAvailableException($e->getMessage(), (int)$e->getCode(), $e);
} catch (NotFoundException $e) {
throw new \OCP\Files\NotFoundException($e->getMessage(), 0, $e);
$this->remove($target);
$result = $this->share->rename($absoluteSource, $absoluteTarget);
} else {
- $this->logger->logException($e, ['level' => ILogger::WARN]);
+ $this->logger->warning($e->getMessage(), ['exception' => $e]);
return false;
}
} catch (InvalidArgumentException $e) {
$this->remove($target);
$result = $this->share->rename($absoluteSource, $absoluteTarget);
} else {
- $this->logger->logException($e, ['level' => ILogger::WARN]);
+ $this->logger->warning($e->getMessage(), ['exception' => $e]);
return false;
}
} catch (\Exception $e) {
- $this->logger->logException($e, ['level' => ILogger::WARN]);
+ $this->logger->warning($e->getMessage(), ['exception' => $e]);
return false;
}
unset($this->statCache[$absoluteSource], $this->statCache[$absoluteTarget]);
} catch (ForbiddenException $e) {
return false;
} catch (ConnectException $e) {
- $this->logger->logException($e, ['message' => 'Error while deleting file']);
+ $this->logger->error('Error while deleting file', ['exception' => $e]);
throw new StorageNotAvailableException($e->getMessage(), (int)$e->getCode(), $e);
}
}
} catch (OutOfSpaceException $e) {
throw new EntityTooLargeException("not enough available space to create file", 0, $e);
} catch (ConnectException $e) {
- $this->logger->logException($e, ['message' => 'Error while opening file']);
+ $this->logger->error('Error while opening file', ['exception' => $e]);
throw new StorageNotAvailableException($e->getMessage(), (int)$e->getCode(), $e);
}
}
} catch (ForbiddenException $e) {
return false;
} catch (ConnectException $e) {
- $this->logger->logException($e, ['message' => 'Error while removing folder']);
+ $this->logger->error('Error while removing folder', ['exception' => $e]);
throw new StorageNotAvailableException($e->getMessage(), (int)$e->getCode(), $e);
}
}
} catch (OutOfSpaceException $e) {
throw new EntityTooLargeException("not enough available space to create file", 0, $e);
} catch (ConnectException $e) {
- $this->logger->logException($e, ['message' => 'Error while creating file']);
+ $this->logger->error('Error while creating file', ['exception' => $e]);
throw new StorageNotAvailableException($e->getMessage(), (int)$e->getCode(), $e);
}
}
$this->share->mkdir($path);
return true;
} catch (ConnectException $e) {
- $this->logger->logException($e, ['message' => 'Error while creating folder']);
+ $this->logger->error('Error while creating folder', ['exception' => $e]);
throw new StorageNotAvailableException($e->getMessage(), (int)$e->getCode(), $e);
} catch (Exception $e) {
return false;
} catch (ForbiddenException $e) {
return false;
} catch (Exception $e) {
- $this->logger->logException($e);
+ $this->logger->error($e->getMessage(), ['exception' => $e]);
return false;
}
}
use OCA\Files_External\Service\UserGlobalStoragesService;
use OCA\Files_External\Service\UserStoragesService;
use OCP\Files\StorageNotAvailableException;
-use OCP\IUser;
use phpseclib\Crypt\AES;
+use Psr\Log\LoggerInterface;
/**
* Class to configure mount.json globally and for users
throw $e;
}
} catch (\Exception $exception) {
- \OC::$server->getLogger()->logException($exception, ['app' => 'files_external']);
+ \OC::$server->get(LoggerInterface::class)->error($exception->getMessage(), ['exception' => $exception, 'app' => 'files_external']);
throw $exception;
}
}
namespace OCA\Files_External\Service;
use OCA\Files_External\Lib\StorageConfig;
-use OCP\ILogger;
+use Psr\Log\LoggerInterface;
/**
* Read mount config from legacy mount.json
$parts = explode('/', ltrim($rootMountPath, '/'), 3);
if (count($parts) < 3) {
// something went wrong, skip
- \OC::$server->getLogger()->error('Could not parse mount point "' . $rootMountPath . '"', ['app' => 'files_external']);
+ \OC::$server->get(LoggerInterface::class)->error('Could not parse mount point "' . $rootMountPath . '"', ['app' => 'files_external']);
continue;
}
$relativeMountPath = rtrim($parts[2], '/');
}
} catch (\UnexpectedValueException $e) {
// don't die if a storage backend doesn't exist
- \OC::$server->getLogger()->logException($e, [
- 'message' => 'Could not load storage.',
- 'level' => ILogger::ERROR,
+ \OC::$server->get(LoggerInterface::class)->error('Could not load storage.', [
'app' => 'files_external',
+ 'exception' => $e,
]);
}
}
use OCP\Files\Config\IUserMountCache;
use OCP\Files\Events\InvalidateMountCacheEvent;
use OCP\Files\StorageNotAvailableException;
-use OCP\ILogger;
+use Psr\Log\LoggerInterface;
/**
* Service class to manage external storage
return $config;
} catch (\UnexpectedValueException $e) {
// don't die if a storage backend doesn't exist
- \OC::$server->getLogger()->logException($e, [
- 'message' => 'Could not load storage.',
- 'level' => ILogger::ERROR,
+ \OC::$server->get(LoggerInterface::class)->error('Could not load storage.', [
'app' => 'files_external',
+ 'exception' => $e,
]);
return null;
} catch (\InvalidArgumentException $e) {
- \OC::$server->getLogger()->logException($e, [
- 'message' => 'Could not load storage.',
- 'level' => ILogger::ERROR,
+ \OC::$server->get(LoggerInterface::class)->error('Could not load storage.', [
'app' => 'files_external',
+ 'exception' => $e,
]);
return null;
}
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IL10N;
-use OCP\ILogger;
use OCP\IRequest;
use OCP\IUserSession;
+use Psr\Log\LoggerInterface;
+use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class GlobalStoragesControllerTest extends StoragesControllerTest {
protected function setUp(): void {
$this->createMock(IRequest::class),
$this->createMock(IL10N::class),
$this->service,
- $this->createMock(ILogger::class),
+ $this->createMock(LoggerInterface::class),
$session,
$this->createMock(IGroupManager::class),
$config
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IL10N;
-use OCP\ILogger;
use OCP\IRequest;
use OCP\IUserSession;
+use Psr\Log\LoggerInterface;
+use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class UserStoragesControllerTest extends StoragesControllerTest {
$this->createMock(IRequest::class),
$this->createMock(IL10N::class),
$this->service,
- $this->createMock(ILogger::class),
+ $this->createMock(LoggerInterface::class),
$session,
$this->createMock(IGroupManager::class),
$config