[英]Display only selected Log4j debug statements
Is it possible to display only those statements in console, which are having certain words. 是否可以仅在控制台中显示具有特定单词的那些语句。
For eq: 对于eq:
logger.debug ( "java: hello " );
logger.debug ( "groovy: hello " );
logger.debug ( "ruby: hello " );
Now, by doing some configuration or whatever, all statements which are starting with groovy: should display. 现在,通过执行某些配置或其他任何操作,应显示以groovy开头的所有语句。
You want to use the log4j StringMatchFilter which is part of the "extras" package from apache logging. 您想使用log4j StringMatchFilter ,它是来自apache日志记录的“extras”包的一部分。
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>
<filter class="org.apache.log4j.varia.DenyAllFilter"/>
</appender>
<root>
<appender-ref ref="CustomAppender"/>
</root>
</log4j:configuration>
What about create your customs Levels 如何创建您的习俗级别
public class Groovy extends Level
And then in the log properties file set those levels as your configuration 然后在日志属性文件中将这些级别设置为您的配置
Hope this helps, David. 大卫,希望这会有所帮助。
SLF4J markers are perhaps suitable for your purposes. SLF4J标记可能适合您的用途。 All printing methods such as debug and info in org.slf4j.Logger
admit a Marker as a first parameter . org.slf4j.Logger
所有打印方法(如debug和info) org.slf4j.Logger
允许将Marker作为第一个参数 。 Moreover, logback-classic, a native SLF4J implementation, ships with a filter called MarkerFilter
which I think does what you want. 此外,logback-classic是一个原生SLF4J实现,附带一个名为MarkerFilter
的过滤器,我认为它MarkerFilter
您的需求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.