In Magento 1 we were able to easily log data using Mage::log('Test log')
. In Magento 2 it is more complicated. Below dirty trick that shouldn’t be used on production enviroment:
$logger = new \Monolog\Logger('logger', [new \Monolog\Handler\StreamHandler(BP.'/var/log/example.log')]);
$logger->info('Debug Message', ['context' => ['customKey' => 'customValue']]);
For production environment please use this method https://devdocs.magento.com/guides/v2.3/config-guide/log/custom-logger-handler.html