我有一个问题,试图拥有一个更通用的appender,它应该很容易捕获我的大多数包记录器。 我有一个CDI应用程序,我的生产者注入了记录器,代码如下
package com.mycompany.common.producers;
import java.util.logging.Logger;
import javax.enterprise.inject.Produces;
import javax.enterprise.inject.spi.InjectionPoint;
public class LoggerProducer {
@Produces
public Logger produceLogger(InjectionPoint injectionPoint){
return Logger.getLogger(injectionPoint.getMember().getDeclaringClass().getName());
}
}
当我定义我的类时,这很好,比如
package com.mycompany.rest;
class RestService {
@Inject
private Logger log;
public void myLogTest(){
log.fine("My log line");
}
}
我定义的所有类都按预期工作 但 我有通用记录器的问题。 我们假设我有两个班级
com.mycompany.rest.RestService; com.mycompany.rest.SecondRestService
当我在Wildfly中定义一个appender时,代码类似于
<logger category="com.mycompany.rest.RestService" use-parent-handlers="true">
<level name="FINE"/>
<handlers>
<handler name="MYCOMPANY"/>
</handlers>
</logger>
<logger category="com.mycompany.rest.SecondRestService" use-parent-handlers="true">
<level name="FINE"/>
<handlers>
<handler name="MYCOMPANY"/>
</handlers>
</logger>
一切都很好,但我想了解,如果我配置这个
<logger category="com.mycompany.rest" use-parent-handlers="true">
<level name="FINE"/>
<handlers>
<handler name="MYCOMPANY"/>
</handlers>
</logger>
根本不起作用。我需要一个包级别的记录器 请帮忙!
答案 0 :(得分:0)
目前我正在评论,但我错过了配置中的处理程序,现在我添加了处理程序,记录器正常工作。