Configuring log4j to filter out unwanted messages in Confluence Data Center application log
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
Be mindful that the steps highlighted below are not supported in Confluence running version >= 8.x
Purpose
The Confluence administrator relies on the application logs to monitor its instance and to troubleshoot issues.
Sometimes there are unwanted messages that could fill in the logs pretty quick and they may not be filtered out using the standard configuration.
Unwanted messages can distract the reader and hide important entries that could be identified more easily if the log file was cleaner.
Before filtering out (suppressing) target messages it is important to perform a proper investigation to determine if these messages are really irrelevant.
A classic example in Confluence is the Broken Pipe message that could flood the application logs and hide any other entry that would be interesting to the administrator.
It was proven that many times this is caused by the Reverse Proxy without any consequence to the Confluence user and removing these messages were not possible through the common configuration.
More information about this type of entry can be found in CONFSERVER-55279 - Logs flooded with "Broken pipe" or other connection errors , which is resolved on Confluence 7.0.5 onward.
This document explains how to use log4j
filtering capabilities to filter out/suppress unwanted messages.
This document is not about Broken Pipe messages, but will use it as an example to setup a sample filter.
Solution
log4j
has a configuration named StringMatchFilter
with which we can take a decision to display or not an entry in the log if it matches the configured filter.
We are going to use this configuration to filter out a target entry using the contents of the message as explained in the steps below.
- Identify your
log4j.properties
file and save a backup copy.- We will perform modifications in the
log4j.properties
file, so it is recommended to save a backup of that file prior to any changes. - This file is located at
<Confluence Installation>/confluence/WEB-INF/classes/log4j.properties
In this file, the standard configuration related to the Confluence application log may look like the below.
log4j.appender.confluencelog=com.atlassian.confluence.logging.ConfluenceHomeLogAppender 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 %m%n
- We will perform modifications in the
- Identify the type of entry you want to filter out/suppress from the Confluence log.
In our example, the entry is similar to the below -- long stack trace removed.
2020-04-20 10:33:34,955 ERROR [http-nio-21310-exec-9] [[Standalone].[localhost].[/c61310].[file-server]] log Servlet.service() for servlet [file-server] threw exception java.lang.RuntimeException: org.apache.catalina.connector.ClientAbortException: java.io.IOException: Broken pipe at com.atlassian.plugin.cache.filecache.impl.StreamsCache.streamFromFile(StreamsCache.java:140) at com.atlassian.plugin.cache.filecache.impl.OneStreamCache.stream(OneStreamCache.java:65) (...) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748) Caused by: org.apache.catalina.connector.ClientAbortException: java.io.IOException: Broken pipe at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:341) at org.apache.catalina.connector.OutputBuffer.flushByteBuffer(OutputBuffer.java:766) (...) at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:2291) at com.atlassian.plugin.cache.filecache.impl.StreamsCache.streamFromFile(StreamsCache.java:135) ... 365 more Caused by: java.io.IOException: Broken pipe at sun.nio.ch.FileDispatcherImpl.write0(Native Method) at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:47) (...) at org.apache.coyote.Response.doWrite(Response.java:599) at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:329) ... 380 more
- In this example we will filter out any entry that contains a message with "
for servlet [file-server] threw exception
". - The stack trace portion of the entry cannot be used in this filter.
Configure the
log4j
filter as the example below.log4j.appender.confluencelog.filter.1=org.apache.log4j.varia.StringMatchFilter log4j.appender.confluencelog.filter.1.StringToMatch=for servlet [file-server] threw exception log4j.appender.confluencelog.filter.1.AcceptOnMatch=false
After adding these lines, your Confluence application log configuration should look similar to the below.
log4j.appender.confluencelog=com.atlassian.confluence.logging.ConfluenceHomeLogAppender 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 %m%n log4j.appender.confluencelog.filter.1=org.apache.log4j.varia.StringMatchFilter log4j.appender.confluencelog.filter.1.StringToMatch=for servlet [file-server] threw exception log4j.appender.confluencelog.filter.1.AcceptOnMatch=false
- Save the modified
log4j.properties
file and restart your Confluence instance.- If you have a Data Center deployment this must be configured on all nodes from your cluster.
Related Content
- Configuring log4j in Confluence to send specific entries to a different log file
- log4j docs - Class PatternLayout
- log4j docs - StringMatchFilter
- Working with Confluence Logs
- Configuring Logging