slf4j +龙目岛+其他记录器

时间:2018-08-07 09:36:17

标签: java slf4j lombok

我想在我的课堂上使用lombok + @ slf4j添加一个额外的记录器。 目前,我正在使用@ Slf4j创建

  

私有静态最终org.slf4j.Logger日志=   org.slf4j.LoggerFactory.getLogger(LogExample.class)。

我正在使用它进行标准日志记录 我想为班级中的特定登录创建另一个记录器。

  

私有静态最终Logger testLog =   LoggerFactory.getLogger(LogExample.class.getName()+“。TestLog”)

将特定日志输出到单独的文件。这是手动工作的。如何使用lombok @ Slf4j

进行配置

1 个答案:

答案 0 :(得分:0)

看起来像龙目岛(Lombok)没有此功能:issue here

也许将来我们会提供此有用的功能。

但是,如果您使用的是CDI框架,则可以在代码中注入额外的记录器。

J2EE方式:

@Produces
Logger produceLogger(InjectionPoint injectionPoint) {
    return LoggerFactory.getLogger(injectionPoint.getMember().getDeclaringClass().getName());
}

注射:

@Inject
private Logger auxLogger;

春季方式:

@Bean
@Scope("prototype")
Logger logger(InjectionPoint injectionPoint){
    return LoggerFactory.getLogger(injectionPoint.getMethodParameter().getContainingClass());
}

注入:

@Autowired
private Logger auxLogger;