NickOSU
NickOSU

Reputation: 85

slf4j logger doesn't print full package name

I have a project with some classes using org.slf4j.Logger to log some information. The loggers in all other classes are working OK and print full class name, e.g. INFO com.myapp.gca.servlet.LoginServlet - Entering login. But for one class, it doesn't print full class name, e.g. INFO c.m.gca.servlet.HealthCheckServlet - GCA health check OK, where com.myapp. is replaced by c.m..

I couldn't find any difference in this particular class from others. The logger is defined like

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

What may be the reason?

Upvotes: 5

Views: 4012

Answers (2)

Nikolas
Nikolas

Reputation: 44378

See the Conversion Word table at the official documentation. You have to configure the logger to the length of at least 40 because of the combined package and class name length:

%logger{40}

However, the %logger would be better which always provides the full name.

Upvotes: 8

Sambit
Sambit

Reputation: 8011

Use %logger{26} in pattern in logback.xml.

For more details, refer this link.

https://logback.qos.ch/manual/layouts.html

Upvotes: 1

Related Questions