membersound
membersound

Reputation: 86915

How to configure log4j2.xml log level for specific class only?

In log4j it's possible to define log levels by package as follows:

    <logger name="org.springframework.web.servlet.mvc.method.annotation" level="info">
        <AppenderRef ref="CONSOLE" />
    </logger>

Questin: how can I define the logging for a specific class only? (eg org.springframework.web.servlet.mvc.method.annotation.EndpointHandlerMapping)? If I just put this into the <logger name property, nothing is logged anymore.

Upvotes: 11

Views: 12585

Answers (1)

Mario Doskoc
Mario Doskoc

Reputation: 151

It should work with fully qualified name as well. Logger.name doesn't have to be package/class only but it could be any name which you want to. When you call LoggerFactory.getLogger("MyLogger"), then you have to use

<Logger name="MyLogger" level="info">
  <AppenderRef ref="CONSOLE"/>
</Logger>

Check what is logged when you use logger for package and use logger name from log. What logger name is logged for this class?

Upvotes: 12

Related Questions