Moodle’s site log report (Site administrationReportsLogs) contains a comprehensive list of the activity on your site. Recorded actions include learners’ use of activities, site administration changes, and background tasks such as those performed by scheduled tasks. By default these entries accumulate over time requiring increasing amounts of storage. This blog post covers the settings governing Moodle’s site logs and includes recommendations for maintaining your site.

The site logging implementation uses Moodle’s plugin architecture which provides a standard approach to implement additional logging requirements. Out of the box Moodle uses the Standard Log Store and by default keeps logs indefinitely. But if your site has been running for a few years, or if it’s quite busy, then these logs can grow very large and become the largest table in your site’s database.

On MySQL or MariaDB you can see the five largest tables with SELECT table_name, ROUND((data_length + index_length) / POW(1024, 2)) AS size_mb FROM information_schema.tables WHERE table_schema = ‘moodle’ ORDER BY data_length + index_length DESC LIMIT 5 (change the table_schema if your site’s database is called something other than moodle).

Under Site administrationPluginsLoggingStandard log you can change “Keep logs for” from “Never delete logs” to something appropriate for your site. 365 days is a good general recommendation but you’ll need to consider any data retention policies you may have. If you set this value too low you won’t have records you may need to manage your site. You might have third party plugins which use the logs to provide reports so this may also be something to consider.

When you set “Keep logs for” older entries get removed by the Log table cleanup scheduled task as part of the site cron. For very large logstores it may take days to remove old entries from the database as the following strategy is used: delete old entries in 24 hour chunks for up to five minutes. Once that five minutes is up cleanup stops until the next time this scheduled task runs — normally 24 hours later — at which point it will continue where it left off.

If your site was upgraded from Moodle 2.6 or earlier, another setting to check is whether legacy logging is enabled. This is the old logging system which the Standard Log replaced in Moodle 2.7 but remains as an option for sites that have third party plugins that use this for reporting. Unless you have this you can disable the legacy log (under Site administrationPluginsLoggingManage log stores) but you may have redundant information in the legacy log table (mdl_log) so a better approach may be to first set “Keep logs for” for the legacy log so that old entries are removed and then disable this at a later date.

The record of activity in the site logs is an important part of your site but these can also take a lot of space with historical data. Implementing a retention period by changing “Keep logs for” from the default of “Never delete logs” is a useful recommendation for site administrators. We’ve built up many such practices and recommendations working with Moodle over the years. To apply our knowledge and experience to your site, get in touch!

About This Author

Leon Stringer

Leon had been working in IT for over 25 years starting out with connectivity systems for ICL mainframes. He also worked for an NHS trust in the West Midlands for nine years but doesn’t like to talk about this. He first encountered Moodle in 2011...