Blog | Technical

How to set up log cleaning in Magento

24/04/2019

Here is an introduction into how to set up log cleaning in Magento.

 

What is Magento Log Cleaning?

Magento is a comprehensive tool that, as well as running the frontend of your website, also retains data from the day-to-day activities by logging it into both the database and files.

While this is a helpful process to have, it can also lead to slower run times and isn’t particularly efficient. The longer your site’s existence, the more information is being held and therefore impacting on site performance.

So, you may need to clean your logs periodically to ensure your website runs as smoothly as possible.

 

Automatic Cleaning

You can set up automatic cleaning for your Magento database by following these steps:

1) Log into your Magento backend

2) Go to System > Configuration

3) Look down the left-hand navigation panel and click on the Advanced tab

4) Under the System sub-heading you will find an option entitled Log Cleaning

5) Change the option to YES to enable Log Cleaning

6) The next dropdown allows you to specific how long the log is kept for. You can choose any time period, though we recommend every 30 days depending upon site activity levels.

7) Once you’ve finished, click Save Config before leaving

 

 

Manual Cleaning

You can also choose to clean your log manually, although we only recommend you try if you are experienced with both databases and Magento.

Log cleaning with SSH

After logging onto your SSH server, navigate your way to the root of your Magento eCommerce shop and enter the following command:

php -f shell/log.php clean

Log cleaning with PHPMyAdmin

Within your database, head to PHPMyAdmin (or another database management tool) and select the following:

  • 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

Once selected, scroll down and click ‘Empty’ from the dropdown option ‘With selected’.

Then click YES and you’re done!

On a related note, you should ensure that your site’s Ts and Cs comply with 2018’s introduced GDPR laws. Do you need to be collecting this information, and can you justify its storage?

 

Log Files

The contents of your /var/log directory can also become bloated over time, especially the system.log and exception.log files.

These are useful for debugging issues and recognising problems but, if you’re not on the lookout for these things, then these files can become very large, very quickly!

You can either turn these off via the Admin’s configuration (Advanced -> Developer -> Log Settings in Magento 1; enabling Production Mode in Magento 2) or periodically deleting the files before they get too large!

Log files such as those provided by a payment gateway are worth holding onto.

And that’s it! If you need any other advice or help with your Magento logs, please get in touch today.