You have to install the new Log4j2LoggingModule( Matchers.any() ). See
http://onami.incubator.apache.org/logging/log4j2.html
I personally prefer slf4j with logback but ymmv.
If you still get NPE:
Field injection happens after initialization block and constructor have run. Only after that will the fields be not null. If you reference field before then you get NPE. Method injection happens next after field injection. You can use method injection to simulate @PostConstruct or use a dedicated annotation such as in the onami-lifecycle.
@InjectLogger Logger log;
CtorInjectedStuff stuff;
@Inject Foo(CtorInjectedStuff stuff){
this.stuff = stuff;
log.info("created"); // null as fields are not yet injected
}
@Inject public void postConstruct(){
log.info("post construct"); // works
}
Sadly you cannot do
@Inject Foo(CtorInjectedStuff stuff, @InjectLogger Logger log){
...
}
as custom injections work only after instance is created.
Note: The @InjectLogger support is implemented using the before mentioned custom injections via MembersInjector.
Imho: injecting the logger doesn't provide enough added value to warrant the extra hassle over plain simple static field but again ymmv.