psr-discovery/log-implementations
Discover available PSR-3 logger implementations at runtime without hard dependencies. Searches for well-known classes and returns the first compatible LoggerInterface instance, ideal for SDKs and libraries; supports multiple popular loggers and mocking/testing options.
Log facade). Enables dynamic logger resolution without hardcoding dependencies, aligning with Laravel’s modular design.Log facade to delegate to Discover::log(), enabling transparent logger switching without breaking existing code.Discover::log() returns null.$this->app->bind(\Psr\Log\LoggerInterface::class, function () {
return Discover::log() ?: new \Monolog\Logger('fallback');
});
Log::driver() to support dynamic discovery:
Log::extend('discovered', function () {
return Discover::log() ?: throw new \RuntimeException('No logger discovered');
});
Discover::logs() to inspect available implementations for runtime decisions (e.g., enabling/disabling features based on logging capabilities).composer.json (e.g., monolog/monolog:^3.0).composer.json conflict rules to block incompatible versions.psr-mock/log-implementation) may inadvertently ship to production if not scoped to dev dependencies.Logs::use('monolog/monolog') in production.composer.json replace rule to block mocks in non-dev environments.singleton: true mode may cause conflicts if not aligned.singleton: true:
$this->app->singleton(\Psr\Log\LoggerInterface::class, function () {
return Discover::log(singleton: true);
});
$logger = Discover::log() ?: new \Monolog\Logger('fallback') ?: new class implements \Psr\Log\LoggerInterface { /* Minimal implementation */ };
testing environments?config/logging.php or environment variables?google/cloud-logging, aws/aws-sdk-php) that should be prioritized for enterprise use cases?Log::discover())?monolog/monolog in the discovered implementations list.yiisoft/log, laminas/laminas-log) without requiring changes to the host application.psr-discovery/log-implementations as a dependency in composer.json.Discover::log() in non-critical paths (e.g., plugins, SDKs) to test auto-discovery.// In a plugin's service provider
$this->app->when(\Your\Plugin::class)
->needs(\Psr\Log\LoggerInterface::class)
->give(fn () => Discover::log());
Log facade to support dynamic discovery:
// app/Providers/AppServiceProvider.php
Log::extend('discovered', function () {
return Discover::log() ?: throw new \RuntimeException('No logger discovered');
});
'default' => env('LOG_CHANNEL', 'discovered'),
$this->app->bind(\Psr\Log\LoggerInterface::class, function () {
return Discover::log() ?: new \Monolog\Logger('fallback');
});
config/logging.php to reflect the change.php-compat).google/cloud-logging).dev environments by default. Explicitly disable mocks in production:
if (app()->environment('production')) {
Logs::use('monolog/monolog');
}
composer.json:
"require": {
"psr-discovery/log-implementations": "^1.1"
},
"require-dev": {
"psr-mock/log-implementation": "^1.0" // For testing
}
config/logging.php to include the discovered driver (if extending the facade).$this->expectsJobs(Job::class)->toBeDispatched();
// Mock logger will capture logs for assertions
google/cloud-logging).psr-discovery/log-implementations for updates (e.g., new supported loggers, PHP version changes).composer.json constraints for discovered loggers (e.g., monolog/monolog:^3.0) to avoid conflicts.Log::discover()). Deprecate the package if replaced by Laravel core.Logs::prefer(),How can I help you explore Laravel packages today?