How to write a message to a log file?

You can write a message to the var/log/debug.log file by the following code:


Magento 1 has much more shorter way to do it:


Magento 2 has shorter ways too: many objects have already the _logger property, so you can call inside such objects:


But it is not the universal solution, because not all objects have the _logger property.

See also:

See also: