Installation:
composer require adheart/logging
Register the bundle in config/bundles.php (if not using Symfony Flex):
Adheart\Logging\LoggingBundle::class => ['all' => true],
Basic Configuration (config/packages/logging.yaml):
logging:
processors:
- message_normalizer
formatter:
schema_version: '1.0.0'
service_name: 'your-service'
service_version: '%env(RELEASE_ID)%'
First Log Test:
$logger = $this->container->get('logger');
$logger->info('Test log', ['key' => 'value']);
Verify output is a valid JSON with service and version fields.
Unified Logging Structure:
SchemaFormatterV1 (JSON format with timestamp, level, message, context, service, trace, version).{
"service": {"name": "your-service", "version": "1.0.0"},
"trace": {"trace_id": "..."}
}
Processor Integration:
message_normalizer: Auto-detects JSON messages and moves them to context.message_json.
$logger->info('{"error": "invalid"}'); // Moves JSON to context
trace: Enriches logs with OpenTelemetry trace context (if otel_trace integration is enabled).Trace Context:
otel_trace in logging.yaml to inject trace_id, span_id, and cf-ray headers:
logging:
integrations:
- otel_trace
Non-Symfony Projects:
use Adheart\Logging\Core\Formatters\SchemaFormatterV1;
use Adheart\Logging\Core\Processors\MessageNormalizerProcessor;
$handler = new StreamHandler('php://stdout');
$handler->setFormatter(new SchemaFormatterV1('1.0.0', 'your-service', '1.0.0'));
$logger = new Logger('app');
$logger->pushHandler($handler);
$logger->pushProcessor(new MessageNormalizerProcessor());
Custom Processors/Providers:
logging.yaml:
logging:
aliases:
processors:
custom_processor: '@app.logging.processor.custom'
trace_providers:
app_provider: '@app.trace.provider'
Formatter Not Applied:
setFormatter() support (e.g., FingersCrossedHandler).StreamHandler, SyslogHandler).Missing Trace Fields:
otel_trace integration not enabled or no active OpenTelemetry span.logging.integrations and ensure spans are created before logging.Configuration Errors:
logging.integrations and aliases sections.JSON Message Handling:
message_normalizer moves JSON to context.message_json but loses the original JSON structure in message. Use explicitly:
$logger->info('Custom message', ['json_data' => json_encode(['key' => 'value'])]);
logging:scan --summary to audit logger usage.
php bin/console logging:scan --format=json
OpenTelemetry\API is initialized before logging.%env(RELEASE_ID)% for dynamic service_version.Custom Processors:
Monolog\Processor\ProcessorInterface and register via aliases.processors.logging:
aliases:
processors:
custom: '@app.processor.custom'
Trace Providers:
Adheart\Logging\Core\Trace\TraceContextProviderInterface for custom trace sources (e.g., AWS X-Ray).aliases.trace_providers.Integrations:
aliases.integrations:
logging:
aliases:
integrations:
custom_integration:
processors: ['trace']
trace_providers: ['app_provider']
trace if not using OpenTelemetry).BufferHandler for batching logs in high-throughput services.SchemaFormatterV1.trace_id propagation across microservices.logging:scan to identify missing loggers or severity levels.How can I help you explore Laravel packages today?