我正在使用 logback 进行日志记录,我发现过滤堆栈跟踪存在一些问题。我有一个这样的结构:
public class Main {
static final Logger logger = (Logger) LoggerFactory.getLogger(Main.class);
public static void main(String[] args) {
logger.debug("Start");
MyObject1 loggingElement = new MyObject1();
loggingElement.logg();
logger.debug("End");
}
}
public class MyObject1 {
public MyObject2 obj;
static final Logger logger = (Logger) LoggerFactory.getLogger(MyObject1.class);
public MyObject1() {
obj = new MyObject2();
}
public void logg() {
obj.loggError();
}
}
public class MyObject2 {
static final Logger logger = (Logger) LoggerFactory.getLogger(MyObject2.class);
public void loggError() {
logger.error("Error info", new Throwable("Error"));
}
}
和这样的配置xml:
<property name="mask"
value="MyObject2"/>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss} | %level | %-4thread | %-21logger | %m%n
</pattern>
</encoder>
</appender>
<root level="${root.level:-TRACE}">
<appender-ref ref="STDOUT" />
</root>
当我运行 main 方法时,我得到如下输出:
12:29:35 | DEBUG | main | com.logging.Main | Start
12:29:35 | ERROR | main | com.logging.MyObject2 | Error info
java.lang.Throwable: Error
at com.logging.MyObject2.loggError(MyObject2.java:11) [bin/:na]
at com.logging.MyObject1.logg(MyObject1.java:17) [bin/:na]
at com.logging.Main.main(Main.java:14) [bin/:na]
12:29:35 | DEBUG | main | com.logging.Main | End
我想删除其中包含“MyObject1”的行,并保持其余的堆栈跟踪不变,就像在这个例子中一样:http: //java.dzone.com/articles/filtering-stack-trace-hell
我试图更改 logback 的配置
<pattern>%d{HH:mm:ss} | %level | %-4thread | %-21logger | %m%n%ex{full,${mask}}
</pattern>
根本不起作用
<pattern>%d{HH:mm:ss} | %level | %-4thread | %-21logger | %m%n%eXe{full,${mask}}
</pattern>
删除整个堆栈跟踪(不是我的解决方案)
任何人都知道有什么可以帮助的吗?