How to rotate Confluence logs overnight and adding date to the filename

Still need help?

The Atlassian Community is here for you.

Ask the community

Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.

Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Purpose

This article explains how to rotate Confluence Application logs overnight and add the date to the filename configured in the log4j.properties file. 

Solution

Confluence uses Apache's log4j logging service. This allows administrators to control the logging behaviour and the log output file.

The logging behaviour for Confluence and Synchrony is defined in the following properties file which is a standard log4j configuration file, as described in the Apache log4j documentation. In our case, this file is located at <CONFLUENCE_INSTALL_HOME>/confluence/WEB-INF/classes/log4j.properties 

Customizing Log Rotation

To rotate the log file overnight and add the date to the filename of the logs, the below changes can be done in the log4j.properties file.

In the example below, it is covered how to modify Confluence application logs ( atlassian-confluence.log ). Similarly, the log4j appender can be modified for other log files like Synchrony logs ( atlassian-synchrony.log  ), Security( atlassian-confluence-security.log  ), Indexing logs( atlassian-confluence-index.log  ) or any other logs configured.

To achieve this, edit the log4j.properties file as:  

#log4j.appender.confluencelog=com.atlassian.confluence.logging.ConfluenceHomeLogAppender
# Comment the above line and uncomment the following 2 lines if you want to log to a specific location
#log4j.appender.confluencelog=org.apache.log4j.RollingFileAppender
log4j.appender.confluencelog.File=[Path_for_logs]/atlassian-confluence.log  
#log4j.appender.confluencelog.LogFileName=atlassian-confluence.log
log4j.appender.confluencelog=org.apache.log4j.DailyRollingFileAppender
log4j.appender.confluencelog.DatePattern='.'yyyy-MM-dd
log4j.appender.confluencelog.Threshold=DEBUG
#log4j.appender.confluencelog.MaxFileSize=20480KB
#log4j.appender.confluencelog.MaxBackupIndex=5
log4j.appender.confluencelog.layout=com.atlassian.confluence.util.PatternLayoutWithContext
log4j.appender.confluencelog.layout.ConversionPattern=%d %p [%t] [%c{4}] %M %enc{%m}{JSON}%n


DatePattern

In the above code, DailyRollingFileAppender is a log4j appender which will rotate the file daily on the basis of the DatePattern configured.

Below are some of the possible DatePatterns in log4j which can be configured to roll log files accordingly:

Date Pattern Rolling Schedule
'.'yyyy-MMRollover at the beginning of each month
'.'yyyy-wwRollover on the first day of each week. The first day of the week depends on the locale.
'.'yyyy-MM-ddRollover at midnight each day.
'.'yyyy-MM-dd-aRollover at midnight and midday of each day.
'.'yyyy-MM-dd-HHRollover at the top of every hour.
'.'yyyy-MM-dd-HH-mmRollover at the beginning of every minute.

Last modified on Mar 12, 2024

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.