![magento 2 set private cache magento 2 set private cache](https://i.stack.imgur.com/knhIu.png)
bin/magento dev:query-log:enable|disableĪs of Magento 2.3.1 version cron log is more extensive and is now logged in var/log/cron.log instead of var/log/system.log Use the following command to enable/disable database logging:ġ. Usage of database logging is highly recommended because it allows us to track all database queries and can help us find performance bottlenecks. By default, database log is saved in var/debug/db.log. bin/magento cache:flush Database LoggingĪnother great Magento 2 functionality is logging database activity. bin/magento setup:config:set –enable-debug-logging=true|falseĢ. To change the default value in default and develop mode following command can be used:ġ. Debug Loggingīy default, Magento writes to the debug log only in default and develop mode, but not in production mode. In some cases it is not necessary to pass logger in constructor as some classes like “Magento\Framework\View\Element\Template” and “Magento\Framework\Model\AbstractModel” already have $_logger property so if you extend one of these classes logger is already available. Note that we are passing \Psr\Log\LoggerInterface in our constructor, as mentioned at the beginning, preference for LoggerInterface is set to Monolog class in di.xml
#MAGENTO 2 SET PRIVATE CACHE HOW TO#
Here is an example of how to use logger in a custom class to log an exception.
![magento 2 set private cache magento 2 set private cache](https://magentip.com/wp-content/uploads/2020/11/web-setup-wizard-1536x735.jpg)
![magento 2 set private cache magento 2 set private cache](http://www.magemonkeys.com/wp-content/uploads/2019/08/configur_cache_Magento.png)
Magento 2 uses dependency injection so in order to use logger in our class we must pass it in our class constructor. There is another method that can be used to log something with an arbitrary level passed as first parameter $this ->_logger -> log ( $level, $message, array $context = array ( ) )Īll exceptions, no matter what log level is used, are saved in var/log/exception.log Using logger class Logger class has 8 levels of logs and methods for each of those levels, usage of these methods depends on the type of the message user is logging.Įach of these methods accepts 2 arguments, first one is the message itself ( string) and the second one is an optional array (for example instance of an Exception object) $this ->_logger -> emergency ( $message, array $context = array ( ) ) //saved in var/log/system.log $this ->_logger -> alert ( $message, array $context = array ( ) ) //saved in var/log/system.log $this ->_logger -> critical ( $message, array $context = array ( ) ) //saved in var/log/system.log $this ->_logger -> error ( $message, array $context = array ( ) ) //saved in var/log/system.log $this ->_logger -> warning ( $message, array $context = array ( ) ) //saved in var/log/system.log $this ->_logger -> notice ( $message, array $context = array ( ) ) //saved in var/log/system.log $this ->_logger -> info ( $message, array $context = array ( ) ) //saved in var/log/system.log $this ->_logger -> debug ( $message, array $context = array ( ) ) //saved in var/log/debug.log (does not work in production mode) Main Magento 2 log class is “Magento\Framework\Logger\Monolog” and is defined in “MAGENTO2_ROOT/app/etc/di.xml” Īs mentioned before Monolog is a powerful logging tool that allows the user to use a wide range of handlers to their benefit, such as logging to files and syslog, sending alerts and e-mails, logging database activity, etc. Magento 2 comes with built-in logging solution based on Monolog Library which will be analyzed further in this article. Logs provide insight into system processes of Magento 2 and are a great tool for tracking errors, significant events, exceptions and many more. In order for the logging library to be properly implemented with Magento 2, it must comply with PSR-3 standard. Logging is an important part of every development process.