From 0a77bfd22b69d5d3323672ff149b3487a028f269 Mon Sep 17 00:00:00 2001 From: Robert Lemke Date: Thu, 15 Aug 2019 08:08:32 +0200 Subject: [PATCH] Improve logging for import into GCS storage --- Classes/GcsStorage.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/Classes/GcsStorage.php b/Classes/GcsStorage.php index d180164..515613c 100644 --- a/Classes/GcsStorage.php +++ b/Classes/GcsStorage.php @@ -194,7 +194,7 @@ public function importResource($source, $collectionName) try { $resource = $this->importTemporaryFile($temporaryTargetPathAndFilename, $collectionName); } catch (\Exception $e) { - throw new Exception(sprintf('Could not import the temporary file from "%s" to to collection "%s": %s', $temporaryTargetPathAndFilename, $collectionName, $e->getMessage()), 1538034191); + throw new Exception(sprintf('Google Cloud Storage: Could not import the temporary file from "%s" to to collection "%s": %s', $temporaryTargetPathAndFilename, $collectionName, $e->getMessage()), 1538034191); } unlink($temporaryTargetPathAndFilename); @@ -322,7 +322,7 @@ public function getStreamByResource(PersistentResource $resource) } catch (NotFoundException $e) { return false; } catch (\Exception $e) { - $message = sprintf('Could not retrieve stream for resource %s (/%s/%s%s). %s', $resource->getFilename(), $this->bucketName, $this->keyPrefix, $resource->getSha1(), $e->getMessage()); + $message = sprintf('Google Cloud Storage: Could not retrieve stream for resource %s (/%s/%s%s). %s', $resource->getFilename(), $this->bucketName, $this->keyPrefix, $resource->getSha1(), $e->getMessage()); $this->systemLogger->log($message, \LOG_ERR); throw new Exception($message, 1446667860); } @@ -346,7 +346,7 @@ public function getStreamByResourcePath($relativePath) if ($e instanceof NotFoundException) { return false; } - $message = sprintf('Could not retrieve stream for resource (gs://%s/%s). %s', $this->bucketName, $this->keyPrefix . ltrim($relativePath, '/'), $e->getMessage()); + $message = sprintf('Google Cloud Storage: Could not retrieve stream for resource (gs://%s/%s). %s', $this->bucketName, $this->keyPrefix . ltrim($relativePath, '/'), $e->getMessage()); $this->systemLogger->log($message, \LOG_ERR); throw new Exception($message, 1446667861); } @@ -429,15 +429,18 @@ protected function importTemporaryFile($temporaryPathAndFilename, $collectionNam ]); } catch (\Exception $exception) { if (!$bucket->exists()) { - throw new \Exception(sprintf('Failed importing the temporary file into storage collection "%s" because the target bucket "%s" does not exist.', $collectionName, $bucket->name())); - } else { - throw $exception; + $message = sprintf('Google Cloud Storage: Failed importing the temporary file into storage collection "%s" because the target bucket "%s" does not exist.', $collectionName, $bucket->name()); + $this->systemLogger->log($message, LOG_ERR); + throw new \Exception($message); } + + $this->systemLogger->log(sprintf('Google Cloud Storage: Failed importing the temporary file into storage collection "%s": %s', $collectionName, $exception->getMessage()), LOG_ERR); + throw $exception; } - $this->systemLogger->log(sprintf('Successfully imported resource as object "%s" into bucket "%s" with MD5 hash "%s"', $sha1Hash, $this->bucketName, $resource->getMd5() ?: 'unknown'), LOG_INFO); + $this->systemLogger->log(sprintf('Google Cloud Storage: Successfully imported resource as object "%s" into bucket "%s" with MD5 hash "%s"', $sha1Hash, $this->bucketName, $resource->getMd5() ?: 'unknown'), LOG_INFO); } else { - $this->systemLogger->log(sprintf('Did not import resource as object "%s" into bucket "%s" because that object already existed.', $sha1Hash, $this->bucketName), LOG_INFO); + $this->systemLogger->log(sprintf('Google Cloud Storage: Did not import resource as object "%s" into bucket "%s" because that object already existed.', $sha1Hash, $this->bucketName), LOG_INFO); } return $resource;