Thursday, February 5, 2015

Oracle Weblogic Server : Enabling Log rotation of .out file

There is no way to rotate out file from Oracle Weblogic Server Console or EM. To enable log rotation of the out log file on a Linux-based system, perform the following steps:
1. Ensure that you have the logrotate binary installed on your operating system:
ls /usr/sbin/logrotate
2. Create a logrotate configuration file (for example, under /home/oracle/ scripts/logrotate.conf) with the following contents, setting [Domain] to your domain name:
/home/oracle/SOA_DOMAIN/servers/soa_Srv01/logs/soa_Srv01.out {
missingok
copytruncate
compress
rotate=5
size=5M
}
3. Create a logrotate status file (for example, under /home/oracle/scripts/ logrotate.status) with the following contents, setting [Domain] to your domain name:
logrotate state -- version 2
"/home/oracle/SOA_DOMAIN/servers/soa_Srv01/logs/soa_Srv01.out" 2012-1-1
4. Add a new crontab entry by typing crontab -e and adding the following line:
0,15,30,45 * * * * /usr/sbin/logrotate -s /home/oracle/scripts /logrotate.status /home/oracle/scripts/logrotate.conf

This will check every 15 minutes to see if it is necessary to rotate the soa_server1.out standard out file based on the rules defined in the logrotate.conf configuration file. If new log files are added, you must ensure that they are added to the status file or they will not be rotated. This can be repeated for other managed servers as necessary.

You can run the cron job manually to test it.
/usr/sbin/logrotate -s 
/home/oracle/scripts/logrotate.status /home/oracle/scripts/logrotate.conf


Note: 
You can apply above steps for any Oracle middlware products like Oracle Weblogic Server, WbCenter, SOA, BPM, IDM etc. As this is a linux cron job, I believe its not WLS version specific.