cancel
Showing results for 
Search instead for 
Did you mean: 

Log cleaning in Magento 2

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!

12 REPLIES 12

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.

 

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.

Was my answer helpful? You can accept it as a solution.
175+ Professional Extensions for M1 & M2
Need a developer?Just visit Contact Us Now

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. 

Re: Log cleaning in Magento 2

Never Delete Report_Event_type table it causes the site breakdown.

Re: Log cleaning in Magento 2

Cleaning Logs via Magento Admin Panel

This method is easier for non technical store owners who don’t want’ to mess directly with the Magento store’s database. To activate log cleaning option in Magento just do the following:

Log on to your Magento Admin Panel. Go to System => Configuration. On the left under Advanced click on System (Advanced = > System). Under system you will see “Log Cleaning” option. Fill the desired “Log Cleaning” option values and click Save.

Cleaning Logs via phpMyAdmin

If you are comfortable with mysql and queries then this method is more efficient and quicker than default Magento Log Cleaning tool. This method also allows your to clean whatever you like, you can even clean tables which aren’t included in default Magento’s Log Cleaning tool.

Open the database in phpMyAdmin In the right frame, click on the boxes for the following tables: dataflow_batch_export

dataflow_batch_import

log_customer

log_quote

log_summary

log_summary_type

log_url

log_url_info

log_visitor

log_visitor_info

log_visitor_online

report_viewed_product_index

report_compared_product_index

report_event

Look to the bottom of the page, then click the drop down box that says “with selected” and click empty. Click Yes on confirmation screen, and this will truncate all the selected tables.

or you can use script to run

TRUNCATE dataflow_batch_export;
TRUNCATE dataflow_batch_import;
TRUNCATE log_customer;
TRUNCATE log_quote;
TRUNCATE log_summary;
TRUNCATE log_summary_type;
TRUNCATE log_url;
TRUNCATE log_url_info;
TRUNCATE log_visitor;
TRUNCATE log_visitor_info;
TRUNCATE log_visitor_online;
TRUNCATE report_viewed_product_index;
TRUNCATE report_compared_product_index;
TRUNCATE report_event;
TRUNCATE index_event;

Keep in mind that we are here to empty (Truncate) selected tables are not drop them. Be very careful when you do this.

Re: Log cleaning in Magento 2

Hello: I'm curious- under my Magento 2.4.3, under Stores>Congfiguration>Advanced>System, although there are a number of settings listed there, there is no " Log Cleaning" option. Please see screenshot: https://snipboard.io/lKngfV.jpg

 

Has this been removed or moved?

Re: Log cleaning in Magento 2

When I truncate table report_event_types, it breaks my product pages(it shows 404 for all my products), this table is small, you should not clean it.

Re: Log cleaning in Magento 2

Did you ever find a solution to this? Mine looks just like the image you have. No option for Log Cleaning.

 

Thanks!