How can the LoggerAwareInterface be used to auto-wire arbitrary instances with a logger in PHP frameworks?

The LoggerAwareInterface can be used to automatically inject a logger instance into arbitrary classes in PHP frameworks. By implementing this interface, the class can have a setLogger() method that will receive the logger instance, allowing for easy logging functionality without the need for manual instantiation. This helps in promoting code reusability and maintainability.

use Psr\Log\LoggerInterface;

class MyClass implements LoggerAwareInterface
{
    protected $logger;

    public function setLogger(LoggerInterface $logger)
    {
        $this->logger = $logger;
    }
}