PDStat
PDStat

Reputation: 5845

Injection of a SLF4J Logger - only injects once

I am wanting to inject a org.slf4j.Logger into classes that need it instead of declaring it as static at the top and specifying the class name eg.

private static final Logger log = LoggerFactory.getLogger(Application.class);

To do so I have created a producer method like so

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

And then I inject it using @Inject but it only seems to do inject for the first class that requests it, all other classes that have a org.slf4j.Logger injection point end up with a NPE

Upvotes: 1

Views: 567

Answers (0)

Related Questions