How to write to the log file

Laravel

logger('Hello');
logger($model);
logger(json_encode($array));

Magento1

Mage::log('Hello', null, 'custom.log', true);
Mage::log(json_encode($array)), null, 'custom.log', true);

Magento2

Write to debug.log:

\Magento\Framework\App\ObjectManager::getInstance()
    ->get(\Psr\Log\LoggerInterface::class)
    ->debug('Hello');
\Magento\Framework\App\ObjectManager::getInstance()
    ->get(\Psr\Log\LoggerInterface::class)
    ->debug(json_encode($array));

Write to custom.log:

(new \Monolog\Logger('custom'))
    ->pushHandler((new \Monolog\Handler\StreamHandler(BP . '/var/log/custom.log'))->setFormatter(new \Monolog\Formatter\LineFormatter(null, null, true, true)))
    ->debug('Hello');
(new \Monolog\Logger('custom'))
    ->pushHandler((new \Monolog\Handler\StreamHandler(BP . '/var/log/custom.log'))->setFormatter(new \Monolog\Formatter\LineFormatter(null, null, true, true)))
    ->debug(json_encode($array));