You should do logrotation by the logrotate daemon instead of the nextcloud server itself.
First of all, move your logfiles out of the netcloud data directory to /var/log/nextcloud/*
sudo mkdir -p /var/log/nextcloud
sudo chown www-data.www-data /var/log/nextcloud
Create this file:
/etc/logrotate.d/nextcloud
var/log/nextcloud/*.log {
su www-data www-data
size 10M
missingok
daily
rotate 7
maxage 30
dateext
dateformat -%Y%m%d
create 640 www-data www-data
compress
delaycompress
}
Here are the main lines used for deleting log files based on age:
rotate 7
: Keeps up to 7 older log files.
maxage 30
: Deletes log files older than 30 days.
You can adjust these values according to your requirements. Note that daily
ensures that log rotation occurs daily. The dateext
parameter adds the current date to the rotated log file name, and dateformat -%Y%m%d
specifies the date in year-month-day format.
You have to change the log settings from your config.php (example):
config/config.php
'logtimezone' => 'Europe/Berlin',
'logfile' => '/var/log/nextcloud/nextcloud.log',
'logfile_audit' => '/var/log/nextcloud/audit.log',
'log.condition' =>
array (
'apps' =>
array (
0 => 'admin_audit',
),
),
'log_query' => false,
'loglevel' => 2,
'log_rotate_size' => 0,
With 'log_rotate_size' => 0,
Nextcloud does not logrotate at all and so it can be carried out by the operating system’s logrotate service, which guarantees GDPR compliency.
Hope this helps!
Much luck,
ernolf