Sunday, August 21, 2011

Log file rotation

In the Managed Server configuration, Logging, "Log file name" you can assign a file name.
If you say
"logs/myserver.log"

it will generate rotated filenames like

myserver.log00001


You can insert a timestamp information in the file name.

Example:
myserver_%yyyy%_%MM%_%dd%_%hh%_%mm%.log

The documentation says:

"To include a time and date stamp in the file name when the log file is rotated, add java.text.SimpleDateFormat variables to the file name. Surround each variable with percentage (%) characters.

For example, if the file name is defined to be myserver_%yyyy%_%MM%_%dd%_%hh%_%mm%.log, the log file will be named myserver_yyyy_mm_dd_hh_mm.log.

When the log file is rotated, the rotated file name contains the date stamp. For example, if the log file is rotated for the first time on 2 April, 2003 at 10:05 AM, the log file that contains the old messages will be named myserver_2003_04_02_10_05.log00001."



If you do not include a time and date stamp, the rotated log files are numbered in order of creation. For example, myserver.log00007.

However this is slightly incorrect:
myserver_%yyyy%_%MM%_%dd%_%hh%_%mm%.log

generates a rotated log file:
myserver_2011_08_21_12_22.log

and not
myserver_2011_08_21_12_22.log00001
as the documentation says.

Anyway the "Limit number of retained files" is respected, even is the progressive number is not the extension.




No comments: