Skip to content

Commit

Permalink
TASK: Add environment data to log message
Browse files Browse the repository at this point in the history
That makes filtering and statistics possible
  • Loading branch information
daniellienert authored and kdambekalns committed Oct 23, 2020
1 parent 1d3bf1c commit 4707c55
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
9 changes: 5 additions & 4 deletions Classes/S3Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Aws\S3\Exception\S3Exception;
use Aws\S3\S3Client;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Log\Utility\LogEnvironment;
use Neos\Flow\ResourceManagement\CollectionInterface;
use Neos\Flow\ResourceManagement\PersistentResource;
use Neos\Flow\ResourceManagement\ResourceManager;
Expand Down Expand Up @@ -307,7 +308,7 @@ public function getStreamByResource(PersistentResource $resource)
return false;
}
$message = sprintf('Could not retrieve stream for resource %s (s3://%s/%s%s). %s', $resource->getFilename(), $this->bucketName, $this->keyPrefix, $resource->getSha1(), $e->getMessage());
$this->systemLogger->error($message);
$this->systemLogger->error($message, LogEnvironment::fromMethodName(__METHOD__));
return false;
}
}
Expand All @@ -330,7 +331,7 @@ public function getStreamByResourcePath($relativePath)
return false;
}
$message = sprintf('Could not retrieve stream for resource (s3://%s/%s%s). %s', $this->bucketName, $this->keyPrefix, ltrim('/', $relativePath), $e->getMessage());
$this->systemLogger->error($message);
$this->systemLogger->error($message, LogEnvironment::fromMethodName(__METHOD__));
return false;
}
}
Expand Down Expand Up @@ -418,9 +419,9 @@ protected function importTemporaryFile($temporaryPathAndFilename, $collectionNam
'ContentType' => $resource->getMediaType(),
'Key' => $objectName
]);
$this->systemLogger->info(sprintf('Successfully imported resource as object "%s" into bucket "%s" with MD5 hash "%s"', $objectName, $this->bucketName, $resource->getMd5() ?: 'unknown'));
$this->systemLogger->info(sprintf('Successfully imported resource as object "%s" into bucket "%s" with MD5 hash "%s"', $objectName, $this->bucketName, $resource->getMd5() ?: 'unknown'), LogEnvironment::fromMethodName(__METHOD__));
} else {
$this->systemLogger->info(sprintf('Did not import resource as object "%s" into bucket "%s" because that object already existed.', $objectName, $this->bucketName));
$this->systemLogger->info(sprintf('Did not import resource as object "%s" into bucket "%s" because that object already existed.', $objectName, $this->bucketName), LogEnvironment::fromMethodName(__METHOD__));
}

return $resource;
Expand Down
5 changes: 3 additions & 2 deletions Classes/S3Target.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Aws\S3\Exception\S3Exception;
use Aws\S3\S3Client;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Log\Utility\LogEnvironment;
use Neos\Flow\ResourceManagement\CollectionInterface;
use Neos\Flow\ResourceManagement\Exception;
use Neos\Flow\ResourceManagement\Publishing\MessageCollector;
Expand Down Expand Up @@ -220,7 +221,7 @@ public function publishCollection(CollectionInterface $collection, callable $cal
$this->systemLogger->debug(sprintf('Successfully copied resource as object "%s" (MD5: %s) from bucket "%s" to bucket "%s"', $objectName, $object->getMd5() ?: 'unknown', $storageBucketName, $this->bucketName));
} catch (S3Exception $e) {
$message = sprintf('Could not copy resource with SHA1 hash %s of collection %s from bucket %s to %s: %s', $object->getSha1(), $collection->getName(), $storageBucketName, $this->bucketName, $e->getMessage());
$this->systemLogger->critical($e);
$this->systemLogger->critical($e, LogEnvironment::fromMethodName(__METHOD__));
$this->messageCollector->append($message);
}
}
Expand Down Expand Up @@ -291,7 +292,7 @@ public function publishResource(PersistentResource $resource, CollectionInterfac
$this->systemLogger->debug(sprintf('Successfully published resource as object "%s" (MD5: %s) by copying from bucket "%s" to bucket "%s"', $objectName, $resource->getMd5() ?: 'unknown', $storage->getBucketName(), $this->bucketName));
} catch (S3Exception $e) {
$message = sprintf('Could not publish resource with SHA1 hash %s of collection %s (source object: %s) through "CopyObject" because the S3 client reported an error: %s', $resource->getSha1(), $collection->getName(), $sourceObjectArn, $e->getMessage());
$this->systemLogger->critical($e);
$this->systemLogger->critical($e, LogEnvironment::fromMethodName(__METHOD__));
$this->messageCollector->append($message);
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"MIT"
],
"require": {
"neos/flow": "^5.0 || ^6.0",
"neos/flow": "^5.2 || ^6.0",
"aws/aws-sdk-php": "~3.0"
},
"autoload": {
Expand Down

0 comments on commit 4707c55

Please sign in to comment.