adrenalinkin/monolog-autowire-bundle
Symfony bundle that enables autowiring of Monolog channel loggers via generated decorator classes, plus a LoggerCollection fallback mechanism. Works even without MonologBundle: missing channels fall back to the default PSR-3 logger or NullLogger.
app, security, audit), improving code consistency and reducing context-switching for developers.NullLogger or default channel).Adopt When:
private LoggerInterface $logger in services) without manual YAML/XML configuration.Look Elsewhere If:
symfony/monolog-bundle extensions or custom solutions)."This package streamlines how our developers access and manage application logs by automating the setup of Monolog channels through Symfony/Laravel’s autowiring system. It reduces manual configuration errors, improves code maintainability, and aligns with our tech stack’s best practices. For example, instead of hardcoding loggers in services, developers can simply declare them as dependencies (e.g., private LoggerInterface $auditLogger), making the codebase more scalable and easier to debug. This is a low-risk, high-reward change that supports our observability goals without requiring new tooling."
*"The Monolog Autowire Bundle solves a pain point in our logging architecture: manual service definitions for Monolog channels. By enabling autowiring, we eliminate redundant YAML/XML configs and reduce the chance of misconfigured loggers. Key benefits:
$securityLogger->error()).NullLogger).MonologBundle, and integrates cleanly with Symfony’s DI container.Proposal: Pilot this in [Module X] to replace manual logger registration. If successful, we can roll it out to other services. The MIT license and minimal dependencies make it a safe bet."*
*"This bundle lets you autowire Monolog loggers like any other service, cutting down on repetitive services.yaml entries. For example:
// Before: Manual config in services.yaml
services:
App\Service\AuditService:
arguments:
$logger: '@logger.audit'
// After: Autowire + type-hinting
class AuditService {
public function __construct(
private LoggerInterface $auditLogger, // Autowired!
private LoggerInterface $appLogger // Fallback if 'app' channel exists
) {}
}
- **No more hunting for logger service IDs** (e.g., `@logger.security`).
- **Fallback logic built-in**: If `$auditLogger` isn’t configured, it defaults to `@Psr\Log\LoggerInterface` (or `NullLogger`).
- **Works with `LoggerCollection`**: Inject a collection to access multiple channels dynamically.
*Try it*: Add the bundle to `composer.json`, and replace manual logger args with autowired properties. Zero breaking changes if you’re already using Monolog!"*
How can I help you explore Laravel packages today?