Reputation: 1417
I would like to add an additional logger in my class using lombok + @slf4j. Currently, I am using @Slf4j which creates
private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(LogExample.class).
I am using this for standard logging I would like to create another logger for specific logging in class.
private static final Logger testLog = LoggerFactory.getLogger(LogExample.class.getName()+".TestLog")
to output specific logs to separate file. This works manually. How can I configure this using lombok @Slf4j
Upvotes: 5
Views: 2248
Reputation: 3393
Looks like Lombok does not have this feature: issue here
Maybe in future we will have this useful feature.
However, if you are using a CDI framework you can inject an extra logger in your code.
J2EE way:
@Produces
Logger produceLogger(InjectionPoint injectionPoint) {
return LoggerFactory.getLogger(injectionPoint.getMember().getDeclaringClass().getName());
}
Injection:
@Inject
private Logger auxLogger;
Spring way:
@Bean
@Scope("prototype")
Logger logger(InjectionPoint injectionPoint){
return LoggerFactory.getLogger(injectionPoint.getMethodParameter().getContainingClass());
}
Inject with:
@Autowired
private Logger auxLogger;
Upvotes: 2