Rotate log by date

Hi, I run the application on an on-premise server and want to rotate the log by date. How can rotate log and m2ee logs to a new file without restarting the application?   Thanks!
1 answers

Hi Phung,

I am not an expert in this matter, but after some web surfing I found this,


To rotate logs in a Mendix application without restarting it, you can use an external log rotation tool such as Logrotate. Here's how you can configure Logrotate to rotate your application's log files by date:

  1. Install Logrotate on your server if it is not already installed.

  2. Create a configuration file for your application's log file rotation. For example, you can create a file named /etc/logrotate.d/myapp with the following content:

/path/to/myapp/logs/*.log { daily missingok rotate 7 compress delaycompress notifempty create 0640 mendix mendix sharedscripts postrotate /usr/bin/killall -HUP m2ee endscript }

bashCopy code


Replace /path/to/myapp/logs with the path to your application's log directory. The daily option tells Logrotate to rotate the log file every day. The missingok option tells Logrotate to not complain if the log file is missing. The rotate option tells Logrotate to keep 7 rotated log files. The compress and delaycompress options tell Logrotate to compress the rotated log files. The notifempty option tells Logrotate to not rotate the log file if it is empty. The create option tells Logrotate to create a new log file with the specified permissions and ownership. The sharedscripts option tells Logrotate to run the postrotate script once for all rotated files, instead of once for each rotated file. The postrotate script sends a SIGHUP signal to the m2ee process, which will cause it to reopen the log file.

  1. Test the log rotation configuration by running the following command:
logrotate -d /etc/logrotate.d/myapp

bashCopy code


This will run Logrotate in debug mode and show you what actions it would take.

  1. If everything looks good, run the following command to actually rotate the log file:


bashCopy code

logrotate -f /etc/logrotate.d/myapp

This will force Logrotate to rotate the log file immediately.

Note that this configuration assumes that your application is running as the mendix user and group. If it is running as a different user and group, you'll need to adjust the create option


Hope it helps!