Search code examples
javaloggingwildfly-8

Wildfly 8.2.0 package level logging category


I have a problem trying to have a more generic appender which should catch easily most of my package loggers. I have a CDI application with the logger injected from my producer, whom code is the following

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());
    }
}

That's quite ok, when I define my classes, like

package com.mycompany.rest;

class RestService {
@Inject
private Logger log;

public void myLogTest(){
log.fine("My log line");
}
}

and any classes I define everything works as expected BUT I have a problem with generic loggers. Let's suppose I have two classes

com.mycompany.rest.RestService; com.mycompany.rest.SecondRestService

When I define an appender in Wildfly, with code similar to

<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>

everything works great, but I'd like to understand, if I configure this

<logger category="com.mycompany.rest" use-parent-handlers="true">
    <level name="FINE"/>
      <handlers>
        <handler name="MYCOMPANY"/>
     </handlers>
</logger>

It doesn't work at all. My need is to have a logger that is package level Please help!


Solution

  • At the moment I was commenting correctly, but I was missing the handler in the configuration, now that I added the handler the logger is working properly.