We can also use Zend log to write the data to the log file.
With below script we can create a log & we can write the message into the log.
$writer = new \Zend\Log\Writer\Stream(BP . ‘/var/log/mylogfile.log’);
$logger = new \Zend\Log\Logger();
$logger->addWriter($writer);
$logger->info($yourmessage);