Skip to content

Commit

Permalink
Merge pull request #52 from CIDgravity/optimize-loggers-and-levels
Browse files Browse the repository at this point in the history
feat: add log line params and update levels
  • Loading branch information
FlorianRuen authored Sep 2, 2024
2 parents 0e6985b + 192c9cd commit 5e7dff5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<name>CidgravityGateway</name>
<summary>An application to display files/directory metadata on decentralized web for CIDgravity storage files</summary>
<description>An application to display files/directory metadata on decentralized web for CIDgravity storage files</description>
<version>1.1.3</version>
<version>1.1.4</version>
<licence>agpl</licence>
<author homepage="https://cidgravity.com">CIDgravity</author>
<author>CIDgravity</author>
Expand Down
34 changes: 23 additions & 11 deletions lib/Event/Listener/UserCreatedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,15 @@ class UserCreatedListener implements IEventListener
{
public function __construct(private LoggerInterface $logger, private IConfig $config, private GlobalStoragesService $globalStoragesService, private Manager $mountManager, private StorageFactory $storageFactory) {}

/**
* Handle UserCreatedEvent to create user folder on Public Filecoin webdav
*/
// Handle UserCreatedEvent to create user folder on Public Filecoin webdav
public function handle(Event $event): void
{
if (!($event instanceof UserCreatedEvent)) {
$this->logger->warning("CIDgravity - UserCreatedEvent: invalid event to create user folder on provided external storage");
return;
}

$this->logger->info("CIDgravity - UserCreatedEvent: will create the user folder on provided external storage",[
$this->logger->debug("CIDgravity - UserCreatedEvent: new user created, will create associated user folder on eligible external storages",[
"user" => json_encode($event->getUser())
]);

Expand Down Expand Up @@ -87,6 +85,12 @@ public function handle(Event $event): void
$resolvedMountpoint = str_replace('$user', $event->getUser()->getUID(), $externalStorage->getBackendOption('root'));
$storageArguments['root'] = $resolvedMountpoint;

$this->logger->info("CIDgravity - UserCreatedEvent: will create user folder on external storage",[
"externalStorage" => json_encode($externalStorage),
"user" => json_encode($event->getUser()),
"resolvedMountpoint" => $resolvedMountpoint,
]);

// get storage instance of type DAV to use mkdir and other functions
$storage = $this->storageFactory->getInstance($mountPointInstance, $storageClass, $storageArguments);

Expand All @@ -95,6 +99,7 @@ public function handle(Event $event): void
$this->logger->debug("CIDgravity - UserCreatedEvent: check type of external storage", [
"storage" => json_encode($storage),
"type" => get_class($storage),
"resolvedMountpoint" => $resolvedMountpoint,
]);

// use instanceOfStorage function instead of php instanceof (not working with instanceof)
Expand All @@ -106,7 +111,8 @@ public function handle(Event $event): void
$this->logger->debug("CIDgravity - UserCreatedEvent: check if user folder already exists", [
"fileExists" => json_encode($fileExists),
"externalStorage" => json_encode($externalStorage),
"user" => json_encode($event->getUser())
"user" => json_encode($event->getUser()),
"resolvedMountpoint" => $resolvedMountpoint,
]);

if (!$fileExists) {
Expand All @@ -115,42 +121,48 @@ public function handle(Event $event): void
$this->logger->debug("CIDgravity - UserCreatedEvent: create user folder", [
"createFolder" => json_encode($createFolder),
"externalStorage" => json_encode($externalStorage),
"user" => json_encode($event->getUser())
"user" => json_encode($event->getUser()),
"resolvedMountpoint" => $resolvedMountpoint,
]);

if (!$createFolder) {
$this->logger->error("CIDgravity - UserCreatedEvent: error while creating the folder for the new user", [
"exception" => $e->getMessage(),
"externalStorage" => json_encode($externalStorage),
"user" => json_encode($event->getUser())
"user" => json_encode($event->getUser()),
"resolvedMountpoint" => $resolvedMountpoint,
]);

} else {
$this->logger->debug("CIDgravity - UserCreatedEvent: user folder successfully created on external storage", [
"externalStorage" => json_encode($externalStorage),
"user" => json_encode($event->getUser())
"user" => json_encode($event->getUser()),
"resolvedMountpoint" => $resolvedMountpoint,
]);
}

} else {
$this->logger->info("CIDgravity - UserCreatedEvent: user folder already exists on external storage", [
"externalStorage" => json_encode($externalStorage),
"user" => json_encode($event->getUser())
"user" => json_encode($event->getUser()),
"resolvedMountpoint" => $resolvedMountpoint,
]);
}

} catch (\Exception $e) {
$this->logger->error("CIDgravity - UserCreatedEvent: unable to check if folder exists or to create folder", [
"exception" => $e->getMessage(),
"externalStorage" => json_encode($externalStorage),
"user" => json_encode($event->getUser())
"user" => json_encode($event->getUser()),
"resolvedMountpoint" => $resolvedMountpoint,
]);
}

} else {
$this->logger->debug("CIDgravity - UserCreatedEvent: external storage not of type DAV", [
"externalStorage" => json_encode($externalStorage),
"user" => json_encode($event->getUser())
"user" => json_encode($event->getUser()),
"resolvedMountpoint" => $resolvedMountpoint,
]);
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "cidgravitygateway",
"description": "An application to display files/directory metadata on decentralized web for CIDgravity storage files",
"version": "1.1.3",
"version": "1.1.4",
"author": "CIDgravity <support@cidgravity.com>",
"bugs": {
"url": "https://github.com/CIDgravity/nextcloud-cidgravity-gateway-app"
Expand Down

0 comments on commit 5e7dff5

Please sign in to comment.