SchemaFormatterV1) for logs, ensuring consistency across microservices—ideal for distributed systems (e.g., Laravel/Symfony APIs, event-driven architectures). This aligns with modern observability practices (e.g., OpenTelemetry compatibility).illuminate/log) with minimal friction. The Symfony Bundle pattern can be adapted via Laravel’s service container (e.g., Laravel\Lumen\Framework\Application or Laravel\SymfonyBridge\BridgeServiceProvider).config/app.php under providers (similar to config/bundles.php in Symfony).logging.yaml with Laravel’s config/logging.php (see Laravel Logging Configuration).| Risk Area | Mitigation Strategy |
|---|---|
| Breaking Changes | Schema v1 is locked; future versions must be backward-compatible. |
| Performance Overhead | Processors (message_normalizer, trace) add minimal latency (~1–5ms per log). |
| Trace Context Gaps | Cloudflare (cf-ray) requires HTTP context; OpenTelemetry must be instrumented. |
| Laravel-Specific Quirks | Custom handlers (e.g., SingleFileHandler) may not support setFormatter(). Use StreamHandler or wrap handlers. |
| Dependency Bloat | nikic/php-parser (for logging:scan) is dev-only; core deps are lightweight. |
Trace Context Reliability:
laravel-otel, ensure OpenTelemetryTraceContextProvider is injected into the logger.Log Schema Evolution:
user_id) to the JSON schema without forking the package?SchemaFormatterV1 via Laravel’s service binding.Legacy Handler Support:
single, daily) are compatible with SchemaFormatterV1?channels.php handlers like Monolog\Handler\FingersCrossedHandler support setFormatter().Observability Tooling:
timestamp format, level as integer).Rollout Strategy:
--dry-run mode (if available) or mock logging:scan.AsyncHandler) support formatters.laravel-debugbar or monolog-test-handler to validate log structure.Phase 1: Schema Adoption (Low Risk)
SchemaFormatterV1:
// config/logging.php
'channels' => [
'structured' => [
'driver' => 'monolog',
'handler' => Monolog\Handler\StreamHandler::class,
'with' => [
'formatter' => Adheart\Logging\Core\Formatters\SchemaFormatterV1::class,
'formatter_with' => [
'schema_version' => '1.0.0',
'service_name' => 'laravel-api',
'service_version' => env('APP_VERSION'),
],
],
],
],
message_normalizer processor to critical loggers:
$logger->pushProcessor(new Adheart\Logging\Core\Processors\MessageNormalizerProcessor());
Phase 2: Trace Integration (Medium Risk)
open-telemetry/opentelemetry-php).otel_trace in config/logging.php (alias-based):
logging:
integrations:
- otel_trace
aliases:
trace_providers:
otel: '@opentelemetry.trace.provider'
"trace": {
"trace_id": "00000000000000000000000000000001",
"span_id": "0000000000000001"
}
Phase 3: Scan & Optimize (High Value)
logging:scan to audit logger usage:
php artisan logging:scan --summary --paths=app/Http
| Component | Laravel Equivalent | Notes |
|---|---|---|
| Symfony Bundle | config/app.php providers |
Register Adheart\Logging\LoggingBundle. |
logging.yaml |
config/logging.php |
Use monolog channel configuration. |
symfony/console |
laravel/console |
logging:scan works via Artisan. |
RequestStack |
Laravel’s Request facade |
For CfRayTraceContextProvider. |
Pre-requisites:
Order of Operations:
composer.json and register bundle.SchemaFormatterV1 in logging.php.app, query).otel_trace and validate traces.logging:scan and iterate.Rollback Plan:
config/app.php:
'providers' => [
// Adheart\Logging\LoggingBundle::class => false,
],
logging:scan tracks logger usage over time.SchemaFormatterV1.logging:scan --list-loggers to identify misconfigured loggers.php artisan log:read --channel=structured | jq .
setFormatter() (e.g., StreamHandler vs. NullHandler).AsyncHandler:
$handler = new Monolog\Handler\AsyncHandler(new StreamHandler('php://stdout'));
logging:scan consumes CPU during analysis (run in CI or staging).| Scenario | Impact | Mitigation | |-----------------------------------|--------------------------------
How can I help you explore Laravel packages today?