log4j 2 extended filter support. You may want to give the RegexFilter
a try.
For log4j 1.2.x there's StringMatchFilter
which is part of the "extras" package.
Here is a quick example found online:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="CustomAppender" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="custom.log"/>
<param name="Append" value="true"/>
<param name="MaxFileSize" value="5000KB"/>
<param name="maxBackupIndex" value="5"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} [%t] %-5p - %m%n" />
</layout>
<filter class="org.apache.log4j.varia.StringMatchFilter">
<param name="StringToMatch" value="Here is DEBUG" />
<param name="AcceptOnMatch" value="true" />
</filter>
</appender>
<root>
<appender-ref ref="CustomAppender"/>
</root>
</log4j:configuration>
However, AFAIU it does not allow you to match wildcards which means dead end in your case I guess. If you dig into the filters source code it should be pretty easy to write your own.