I want to log info to a specific file in magento2.
This does the job:
$writer = new \Zend\Log\Writer\Stream(BP . '/var/log/test.log');
$logger = new \Zend\Log\Logger();
$logger->addWriter($writer);
$logger->info('Your text message');
but I want to use it with DI.
I am getting this error:
Missing required argument $streamOrUrl of Zend\Log\Writer\Stream.
I am not sure about the syntax of DI when there are required parameters. Tried a few ways but it doesn't work:
use Zend\Log\Writer\Stream;
use Zend\Log\Logger;
public $logger;
public $writer;
public function __construct(
Logger $logger,
Stream $writer
) {
$this->logger = $logger;
$this->writer = $writer;
$this->logger->addWriter($this->writer(BP . '/var/log/test.log'));
$this->logger->info('Start');
}
If someone can show me how to use \Psr\Log\LoggerInterface
to write to a custom log file it will be even better.
Thanks!