Writing a message to a system log in Magento 2

- Magento 2

Magento 2 Development

To create a message to a system log in Magento 2.0, use the code listed below:

In Magento 1, for instance, this code was more simple:

but you can also utilize another approach in case of Magento 2. Since there is a  _logger property related to many objects, you can perform the same task by calling inside such objects. Just use the following code:

Please note that not every object has the _logger property. Thus, this method will not work with all your objects.

More tips from Magento 2 Developer’s Cookbook

'

Source

'