Log file Rolling is not working. Appender.rolling.strategy.max is not serving the purpose

Which IIQ version are you inquiring about?

8.2. p4

Rolling of Logsfiles are not happening. Appender.rolling.strategy.max is set to 15. Still only 2 files are present in the folder. All the remaining files are getting deleted. Attached the log4j.properties.

Does anyone else faced the same issue?
Any other settings should I check for keeping 15 files?

Thanks
Divya
18188log4j.properties (15.6 KB)

Try below one:

# Below is an example of how to create a logger that writes to a file.
# Uncomment the following five lines, then uncomment the 
# rootLogger.appenderRef.file.ref definition below
appender.file.type=File
appender.file.name=file
appender.file.fileName=F:/My SailPoint Practice/Logging/sailpoint.log
appender.file.layout.type=PatternLayout
appender.file.layout.pattern=%d{ISO8601} %5p %t %c{4}:%L - %m%n

# used by queue processing to log messages that could not be processed
appender.discards.type=RollingFile
appender.discards.name=discards
appender.discards.fileName=${logLocation}${discardsFilename}.log
appender.discards.filePattern=${discardsFilename}-%d{MM-dd-yyyy}-%i.log
appender.discards.layout.type=PatternLayout
appender.discards.layout.pattern=%m%n
appender.discards.policies.type=Policies
appender.discards.policies.size.type=SizeBasedTriggeringPolicy
appender.discards.policies.size.size=10MB
appender.discards.strategy.type=DefaultRolloverStrategy
appender.discards.strategy.max=15

You can change this according to your location. Restart servers after you made changes, just relogging is also sufficient, But you can give a try.

@divsubha ,

When using date patterns in the filePattern of your RollingFileAppender, the max parameter in DefaultRolloverStrategy does not limit the number of log files. This is why you’re observing that only 2 files are present, despite setting appender.rolling.strategy.max=15. The max parameter works when the filePattern includes only an integer index (like %i), not when it includes date patterns (like %d{dd-MMM}).

To retain a specific number of log files when using date patterns, you need to configure a Delete action within your rollover strategy. This action allows you to specify conditions under which old log files should be deleted.

Here’s how you can modify your log4j2.properties file to keep 15 log files:

# Rolling Enable
appender.rolling.type=RollingFile
appender.rolling.name=IIQRFile
appender.rolling.fileName=E:/logs/sailpoint.log
appender.rolling.filePattern=E:/logs/sailpoint-%d{dd-MMM}-%i.log.gz
appender.rolling.layout.type=PatternLayout
appender.rolling.layout.pattern=%d{ISO8601} %5p %t %c{4}:%L - %m%n
appender.rolling.policies.type=Policies
appender.rolling.policies.size.type=SizeBasedTriggeringPolicy
appender.rolling.policies.size.size=10MB
appender.rolling.strategy.type=DefaultRolloverStrategy

# Add the Delete action to manage old log files
appender.rolling.strategy.delete.type=Delete
appender.rolling.strategy.delete.basePath=E:/logs
appender.rolling.strategy.delete.maxDepth=1
appender.rolling.strategy.delete.ifFileName.type=IfFileName
appender.rolling.strategy.delete.ifFileName.glob=sailpoint-*.log.gz
appender.rolling.strategy.delete.ifAny.type=IfAccumulatedFileCount
appender.rolling.strategy.delete.ifAny.exceeds=15

Explanation:

  • Delete Action Configuration:
    • appender.rolling.strategy.delete.type=Delete: Defines a delete action.
    • appender.rolling.strategy.delete.basePath=E:/logs: Sets the base directory for deletion.
    • appender.rolling.strategy.delete.maxDepth=1: Limits the depth of directory traversal.
    • appender.rolling.strategy.delete.ifFileName.type=IfFileName: Adds a condition based on file name.
    • appender.rolling.strategy.delete.ifFileName.glob=sailpoint-*.log.gz: Specifies the pattern of files to consider.
    • appender.rolling.strategy.delete.ifAny.type=IfAccumulatedFileCount: Adds a condition based on file count.
    • appender.rolling.strategy.delete.ifAny.exceeds=15: Sets the maximum number of files to retain.

Mark it as solved, If it works.

1 Like

Hi Bhanu Prakash,

Thanks for your note. The only difference I’m seeing between yours and mine are in the line “appender.discards.layout.pattern”. Yours is %m%n and mine is “%d{ISO8601} %5p %t %c{4}:%L - %m%n”. Are you saying this causes the issue? and should I try with layout pattern %m%n only?

Thanks
Divya M

Hi @bhanuprakashkuruva @officialamitguptaa

Thanks for your note. I observed that log rolling is not working on the days if last year’s file is also present with same date. Log file name pattern in our server is sailpoint.dd.mm.%i.log. As it doesn’t have year in the name, the logger considers the previous year file and gives the file name with series continued from last year’s.

The weird behavior is that it is not deleting the previous year’s file even the series reaches the maximum count.

Kindly share your thoughts on this if you have any. Whether the logger won’t be able to modify the previous year’s file?

Thanks
Divya M

@divsubha -

You’re experiencing this issue because your log file naming pattern does not include the year. As a result, when the date rolls over to the same day and month in a new year, the logger encounters files with the same date in their names from the previous year. This causes several problems:

  1. File Naming Collision: Since the files from the previous year have the same date in their names, the logger considers them when determining the next index %i to use. This leads to the logger continuing the numbering sequence from last year’s files instead of starting anew.
  2. Deletion Policy Not Deleting Old Files: The deletion policy may not be deleting the previous year’s files because it sees the accumulated file count as not exceeding the maximum you set, or because the files don’t match the conditions specified in the delete action.

Solution: Include the Year in Your File Naming Pattern

To resolve this issue, you should modify your filePattern to include the year in the file name. Here’s how you can adjust your configuration:

# Rolling Enable
appender.rolling.type=RollingFile
appender.rolling.name=IIQRFile
appender.rolling.fileName=E:/logs/sailpoint.log
appender.rolling.filePattern=E:/logs/sailpoint-%d{yyyy-MM-dd}-%i.log.gz
appender.rolling.layout.type=PatternLayout
appender.rolling.layout.pattern=%d{ISO8601} %5p %t %c{4}:%L - %m%n
appender.rolling.policies.type=Policies
appender.rolling.policies.size.type=SizeBasedTriggeringPolicy
appender.rolling.policies.size.size=10MB
appender.rolling.strategy.type=DefaultRolloverStrategy

# Add the Delete action to manage old log files
appender.rolling.strategy.delete.type=Delete
appender.rolling.strategy.delete.basePath=E:/logs
appender.rolling.strategy.delete.maxDepth=1
appender.rolling.strategy.delete.ifFileName.type=IfFileName
appender.rolling.strategy.delete.ifFileName.glob=sailpoint-*.log.gz
appender.rolling.strategy.delete.ifAny.type=IfAccumulatedFileCount
appender.rolling.strategy.delete.ifAny.exceeds=15

Explanation:

  • Include Year in File Names: By including %d{yyyy-MM-dd} in your filePattern, each log file’s name will now include the year, month, and day. This prevents file naming collisions from year to year.
  • Preventing Index Continuation from Previous Year: This change ensures that the logger does not consider previous year’s files when determining the next index %i, as the date portion of the file name is different.
  • Adjust Deletion Policy: Ensure that your deletion policy (Delete action) is set to match the new file naming pattern, so it can correctly identify and delete old log files, including those from previous years if necessary.

Addressing the Deletion of Previous Year’s Files

The deletion policy may not be deleting previous ye ar’s files because the conditions in the Delete action may not be met. For example, the accumulated file count might not exceed your set limit due to how the files are counted or matched.

To ensure that previous year’s files are also deleted when appropriate, you might need to adjust the deletion policy conditions. You can use the IfLastModified condition to delete files older than a certain age. Here’s how you can modify your Delete action:

# Adjusted Delete action to delete files older than 30 days
appender.rolling.strategy.delete.type=Delete
appender.rolling.strategy.delete.basePath=E:/logs
appender.rolling.strategy.delete.maxDepth=1
appender.rolling.strategy.delete.ifFileName.type=IfFileName
appender.rolling.strategy.delete.ifFileName.glob=sailpoint-*.log.gz
appender.rolling.strategy.delete.ifLastModified.type=IfLastModified
appender.rolling.strategy.delete.ifLastModified.age=30D

Explanation:

  • Delete Files Older Than 30 Days: The IfLastModified condition with age=30D ensures that log files older than 30 days are deleted, which includes previous year’s files that are older than 30 days.
  • Combining Conditions: The Delete action will delete files matching the file name pattern and the last modified age condition.

Why the Logger Doesn’t Modify Previous Year’s Files

The logger cannot modify previous year’s files if they are set to be read-only or if the application does not have permission to overwrite them. Additionally, with the year included in the file name, the logger treats each year’s files separately and doesn’t attempt to continue the index from previous years.

Hope this helps.

1 Like