Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to keep the TYPO3 sys_log nice & clean?

Tags:

typo3

I have this MySQL

DELETE FROM sys_log 
WHERE sys_log.tstamp < UNIX_TIMESTAMP(ADDDATE(NOW(), INTERVAL -2 MONTH)) 
ORDER BY sys_log.tstamp ASC 
LIMIT 10000

Is this good for keeping the sys_log small, if I cronjob it?

like image 503
yunzen Avatar asked Jun 27 '12 16:06

yunzen


4 Answers

Since TYPO3 9, the history is no longer stored using sys_log.
You can safely delete records from sys_log.

See Breaking Change #55298.

Short answer:

No, it is definitely not a good idea (unless you are using TYPO3 9 or higher, see note at the bottom of this post). If you really want to delete stuff from sys_log, keep in mind that sys_history is still referencing it. You should do the same for sys_history too.

Or, just do the following:

DELETE FROM sys_log WHERE NOT EXISTS 
(SELECT * FROM sys_history WHERE sys_history.sys_log_uid=sys_log.uid) 
AND recuid=0 AND tstamp < $timestamp LIMIT $limit 

Feel free to optimize this for your requirements.

What you can also do safely (without affecting sys_history) is deleting records with sys_log.error != 0.

Some more recommendations:

  • Set your debugging level to verbose (Warnings) on development but errors-only in production
  • Regularly look at the sys log and eliminate problems. You can delete the specific error from the sys_log once you have taken care of the problem (see sys_log.error != 0, sys_log.details). You can do this with a database command or on newer TYPO3 versions use the "SYSTEM: log" in the backend and use the "Delete similar errors" button:

enter image description here

  • You can also consider, doing a truncate sys_log and truncate sys_history together with using the lowlevel cleaner and delete records with deleted=1 on a major version upgrade. Be sure to talk with someone in close vicinity to the editors first though, as this will remove the entire history. Be sure that you will want to do that.

For the scheduler task "Table garbage collection" see the documentation: https://docs.typo3.org/c/typo3/cms-scheduler/master/en-us/Installation/BaseTasks/Index.html

like image 200
Sybille Peters Avatar answered Nov 12 '22 07:11

Sybille Peters


There is a scheduler task for this.

It is called Table garbage collection (scheduler).

In TYPO3 4.7, it can only clean the sys_log table. Starting from TYPO3 6.0, it can also clean the sys_history table. You can configure the number of days and what tables to clean.

Extensions may register further tables to clean.

like image 43
pgampe Avatar answered Nov 12 '22 06:11

pgampe


Yes and No

It IS NOT if you care about your record history. You can revert changes to records (content, pages etc.) using the sys_history table. The sys_history tables and sys_log tables are related. When you truncate sys_log, you also loose the ability to rollback any changes to the system. Your clients may not like that.

It IS if you only care about the sys_log size. Truncating the table via cron is fine.

In TYPO3 4.6 and up you can use the Table garbage collection scheduler task als pgampe says. For TYPO3 versions below 4.5 you can use the tablecleaner extension. If you remove all records from sys_log older than [N] days, you will also retain your record history for [N] days. That seems to be the best solution to me.

And please try to fix what is filling your sys_log in the first place ;-)

like image 45
Michiel Roos Avatar answered Nov 12 '22 07:11

Michiel Roos


Yes, it is.

See also other suggestions by Jochen Weiland about keeping TYPO3 installation clean and small

like image 43
biesior Avatar answered Nov 12 '22 07:11

biesior