PHP code example of herdwatch-oss / monolog-ecs-formatter
1. Go to this page and download the library: Download herdwatch-oss/monolog-ecs-formatter library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
herdwatch-oss / monolog-ecs-formatter example snippets
$log->info('User authenticated', [
new Service('billing-svc', version: '1.4.0', environment: 'prod'),
new User(id: 42, email: '[email protected]'),
new Tracing($traceId, $transactionId),
'request_id' => $requestId, // plain context — stays under "context", not promoted
]);
// ✅ Recommended — positional
$log->error('Sync failed', [
new EcsError($e),
new Service('billing-svc'),
Labels::create()->add('tenant', 'acme'),
]);
// ⚠️ Works, but the key is redundant (it is NOT used to route the field)
$log->error('Sync failed', ['error' => new EcsError($e)]);