cancel
Showing results for 
Search instead for 
Did you mean: 

Log cleaning in Magento 2

Highlighted

Log cleaning in Magento 2

Is there any way to clean logs and tables automatically in Magento 2 server? The logs are just flooding unless I delete them manually. Frequently it leads to server downtime as well. 

This github issue mentions that no such commands are available in Magento 2 unlike Magento 1 where log cleaning was available via admin as well as commands. But that is a pretty old one, hence the ask. Couldn't find many helpful posts either. 

Any suggestions will be helpful, thanks in advance!

4 REPLIES 4
Highlighted

Re: Log cleaning in Magento 2

I was going to say just clean it once a week or something because some people actually read logs for various purposes. 

 

if you want them off  :

bin/magento setup:config:set --enable-debug-logging=false
 bin/magento cache:flush

 By default, Magento writes to the debug log install_directory/var/log/debug.log) when it is in default or develop mode, but not when it is in production mode. 

 

is better to have them because is were people go first and check errors. 

 

just set a cron to delete once a week. if the log is reaching gigabites levels once a week then something is wrong already.

 

Highlighted

Re: Log cleaning in Magento 2

Hello

Try running below SQL query in your database

 

SET foreign_key_checks = 0;
TRUNCATE customer_log;
TRUNCATE customer_visitor;
TRUNCATE report_compared_product_index;
TRUNCATE report_event;
TRUNCATE report_event_types;
TRUNCATE report_viewed_product_aggregated_daily;
TRUNCATE report_viewed_product_aggregated_monthly;
TRUNCATE report_viewed_product_aggregated_yearly;
TRUNCATE report_viewed_product_index;
TRUNCATE product_alert_stock;
TRUNCATE search_query;
TRUNCATE catalogsearch_fulltext_scope1;
TRUNCATE sales_bestsellers_aggregated_yearly;
TRUNCATE sales_bestsellers_aggregated_monthly;
TRUNCATE sales_bestsellers_aggregated_daily;
SET foreign_key_checks = 1;

It will clear all the cache, you can make this trigger and configure it within your phpmyadmin to run it automatically at specified time.

Found something useful, "Kudos" and "Accept as Solution" for Token of Appreciation.

Magento Tutorials
Highlighted

Re: Log cleaning in Magento 2

there is an error when running the sql:

 

Error
consulta SQL:

TRUNCATE report_event_types
MySQL ha dicho: Documentación

#1701 - Cannot truncate a table referenced in a foreign key constraint (`demomagento2_bd`.`report_event`, CONSTRAINT `REPORT_EVENT_EVENT_TYPE_ID_REPORT_EVENT_TYPES_EVENT_TYPE_ID` FOREIGN KEY (`event_type_id`) REFERENCES `demomagento2_bd`.`report_event_types` (`eve)

Re: Log cleaning in Magento 2

Hey!

I think there isn't an option available to clear the logs for the Magento app via the admin panel. If you are facing a problem with logs management and want to clear, you can do it by configuring cron job management for clearing logs automatically. 

I hope, you find your answer. If you still have any queries, feel free to ping me.