Skip to content

How to create custom log file in magento 2

Can anyone help me in creating custom logger file in mmagento 2.
I want to display collection object in log file.
So far, i have tried this code but did not work.
getting $collection object from public function massAction(AbstractCollection $collection)

$writer = new ZendLogWriterStream(BP . '/var/log/pdf.log');
    $logger = new ZendLogLogger();
    $logger->addWriter($writer);
    $logger->info("Hello");
    $logger->info(print_r($collection->debug())); 

This is what i have tried yet.