Replies: 1 comment
-
You could register a resolving callback to do this, but since you mention that you sometimes don't need a logger, you'd have to add some additional logic to determine whether to inject the logger or not. use Illuminate\Foundation\Application;
use Illuminate\Support\ServiceProvider;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerInterface;
class AppServiceProvider extends ServiceProvider
{
public function register(): void
{
$this->app->resolving(LoggerAwareInterface::class, function (LoggerAwareInterface $object, Application $app) {
$object->setLogger($app->make(LoggerInterface::class));
});
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Add support for setting a logger when resolving classes that implement
LoggerAwareInterface
.I know that I could require a logger in a constructor, or in any other method where Laravel resolves dependencies, but sometimes I don't need a logger it's just a nice to have.
I can handle not having one much more easily now that I can use the null safe operator, and therefore use logger calls like comments.
Beta Was this translation helpful? Give feedback.
All reactions