elastic/ecs-logging package provides a standardized way to structure logs using the Elastic Common Schema (ECS), which is ideal for applications requiring observability, centralized logging, and analytics (e.g., Laravel apps integrated with ELK Stack, Datadog, or other SIEM tools).Log::withContext().$logger = new Monolog\Logger('name');
$logger->pushProcessor(new \Elastic\EcsLog\Processor());
LogRequest) or events (Logging events) to inject ECS fields dynamically.database log driver, ECS formatting would require a custom handler (higher effort but feasible).elastic/ecs-logging + monolog as dependencies. Assess if existing logging setup can absorb this without conflicts.error.stack_trace vs. Laravel’s exception formatting)?error_log(), custom file handlers) or databases as primary log sinks.Phase 1: Pilot
single driver for debugging).event.dataset for Laravel-specific logs).Phase 2: Full Rollout
config/logging.php:
'channels' => [
'ecs' => [
'driver' => 'single',
'handler' => Monolog\Handler\StreamHandler::class,
'processors' => [
new \Elastic\EcsLog\Processor(),
],
],
],
ecs.tags.environment).Phase 3: Pipeline Sync
UuidProcessor) but order matters (ECS should run last).composer require elastic/ecs-logging monolog/monolog
config/logging.php to include ECS processor.Log::withContext(['ecs' => ['service.name' => 'laravel-app']])).error.message, http.request.method).log.level missing).ecs.version).log.level: error AND service.name: api). However, debugging may require familiarity with ECS field names.Log::debug() with ECS context to trace issues in production.Monolog\Handler\AsyncHandler to batch logs.error level only).keyword for high-cardinality fields (e.g., user.id).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| ECS Processor Crashes | Logs fail silently | Wrap in try-catch; log raw if ECS fails. |
| Schema Mismatch in ELK | Logs unindexable or corrupted | Validate ECS fields pre-deployment. |
| High Latency in Log Processing | Timeouts in production | Throttle log volume or use async. |
| Custom Fields Break Parsing | Downstream tools fail | Document custom fields; avoid ECS reserved names. |
ecs.tags.environment = 'production').event.dataset: laravel AND response.status_code: 500).debug level) before enforcing ECS for all logs.How can I help you explore Laravel packages today?