Magento 2 Write Messages Log file

Follow the below steps to write messages to log file.

1) Declare a variable.

protected $logger;

2) Initialize object

public function __construct(\Psr\Log\LoggerInterface $logger) {
$this->logger = $logger;
}

3) Now you can log the message as follows

$this->logger->info($message);
$this->logger->debug($message);

Leave a Reply

Your email address will not be published. Required fields are marked *