Skip to content

Instantly share code, notes, and snippets.

@timkelty
Last active May 9, 2024 01:50
Show Gist options
  • Save timkelty/186dad653e72b42eb1401c559881bb39 to your computer and use it in GitHub Desktop.
Save timkelty/186dad653e72b42eb1401c559881bb39 to your computer and use it in GitHub Desktop.
Craft 5 Logging Example
<?php
use craft\helpers\App;
return [
'id' => App::env('CRAFT_APP_ID') ?: 'CraftCMS',
'components' => [
'log' => [
'targets' => [
function() {
// @see https://craftcms.com/docs/5.x/system/logging.html#targets for filtering options
$target = new \craft\log\MonologTarget([
'name' => 'azure-blob',
]);
$connection = 'DefaultEndpointsProtocol=https;AccountName=<name>;AccountKey=<key>';
$client = \MicrosoftAzure\Storage\Blob\BlobRestProxy::createBlobService($connection);
$handler = \Blue32a\Monolog\Handler\AzureBlobStorageHandler($client, 'container', 'append-blob.log');
$target->getLogger()->setHandlers([$handler]);
return $target;
},
]
]
],
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment