---
title: "Rotation of Log files"
slug: "guide/configuration/server-start-up-file/rotation-of-log-files"
sidebar:
  order: 30
---

<a id="ref-16d6e68c19a7"></a>
<a id="ref-e901b6ac4559"></a>

If rotation of log files is not enabled, a log file named `app_YYYY-mm-dd_HHhMMmSS.LLL.log` is created when the server starts and written to until the server terminates.

If rotation of log files is enabled, log messages are written to `<appkey>.log` until the log file is rotated. Rotation of a log file renames it into `<appkey>.log-YYYYmmdd`, optionally followed by a minus sign and a serial number and, if compressed, by suffix `.gz`. The serial number is used if more than one rotation happens per day.

The logging subsystem checks whether or not to rotate whenever (and prior to) a log message is written unless the last check was less than five minutes ago. If the check determines that the log file should be rotated, the current log file is closed, renamed, and optionally compressed, a new log file is created, and old log files are deleted if the current number of rotated log files exceeds the configured number.

The following application properties can be used to control rotation of log files:

## Synopsis

`egr.eai.logrotate.ngen=<integer>`

**Default Value:** `-1`

Controls the maximum number of rotated log files to keep until they are automatically deleted. Allowed values are within -1 and 2^31-1, both inclusive. If set to -1, rotation of log files is disabled. Otherwise it is enabled.

## Synopsis

`egr.eai.logrotate.min_size=<integer>`

**Default Value:** `0`

Log files smaller than the size (in kilo bytes) specified by this option are never rotated. Allowed values are within 0 and 2^63-1, both inclusive.

## Synopsis

`egr.eai.logrotate.max_size=<integer>`

**Default Value:** `0x7fffffffffffffff`

Log files greater than the size (in kilo bytes) specified by this option are always rotated (as soon as the check is done as described above), no matter what the value of property `egr.eai.logrotate.when`. Allowed values are within the value specified as the minimum size and 2^63-1, both inclusive.

## Synopsis

`egr.eai.logrotate.when=<string:>`

May be used to specify the minimum time between log file rotations and a time when rotation shall take place. The syntax, in EBNF, is as follows:

```text
when ::= interval? timespec?
interval ::= digit+
timespec ::= ( '@' date-time? ) | ( '$' period? )
date-time ::= ( ( year? month )? day )?
              'T'
              ( hour ( minute ? second? )? )?
period ::= ( 'D' hour-of-day )
         | ( 'W' day-of-week ( 'D' hour )? )
         | ( 'M' day-of-month ( 'D' hour )? )

year ::= digit digit digit digit   // 0001..9999
month ::= digit digit              // 01..12
day ::= digit digit                // 01..31
hour ::= digit digit               // 00..23
minute ::= digit digit             // 00..59
second ::= digit digit             // 00..59
hour-of-day ::= digit? digit       // 0..23
day-of-week ::= digit              // 0..7, with both 0 and
                                   // 7 representing Sunday
day-of-month ::= (digit? digit)    // 1..31
               | [Ll]              // 'L' and 'l' indicate
                                   // last day of month
digit ::= [0-9]
```

If the value of this property is an empty string (the default), the decision whether or not to rotate the log file is solely based on the maximum size (thus, with both `max_size` and `when` set to their default values, no rotation takes place).

Otherwise, the time the log file should be rotated next is determined as follows:

1. The time of next rotation is set to the time of the last rotation (the modification time of the most recently rotated log file, or the time the application has been started if no rotated log file exists).
2. If an interval has been specified, the interval is treated as a number of hours and added to the next rotation time.
3. If a rotation time has been specified, the time of next rotation is adjusted to the smallest possible value greater than the current value that matches specified time. Unspecified year, month, day(-of-month) and day-of-week do not cause an adjustment, whereas unspecified hour, minute and second set the corresponding field to zero.

Finally, if the time of next rotation is less than or equal to the current time, the log file is rotated.

**Examples:**

| Value | Description |
| --- | --- |
| `10` | rotate every ten hours |
| `@01T01` | rotate the first day of each month at 01:00 AM |
| `47$D23` | rotate every 47 hours, but wait until 11:00 PM |
| `$W5D23` | rotate every Friday at 11:00 PM |
| `$M1` | rotate the first day of each month at midnight |
| `$MLD23` | rotate the last day of each month at 11:00 PM |
