Skip to content

Commit

Permalink
feat: add log line params and update levels
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianRuen committed Sep 2, 2024
1 parent 0e6985b commit d4e9d26
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions lib/Event/Listener/UserCreatedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function handle(Event $event): void
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 +87,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 +101,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 +113,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 +123,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

0 comments on commit d4e9d26

Please sign in to comment.