Skip to content

Commit

Permalink
Improve logging for import into GCS storage
Browse files Browse the repository at this point in the history
  • Loading branch information
robertlemke committed Aug 15, 2019
1 parent 78c76b2 commit 0a77bfd
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions Classes/GcsStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 0a77bfd

Please sign in to comment.