0

I checked log4j setup in my tomcat environment. Although there is no log4j-web.jar file in my webapp or in "common libs" folder, log4j is initialized properly. I only added log4j.properties in my classpath. And that's it, log4j is working.

I am using spring mvc, sl4j-api.jar and sl4j-jcl.jar are in my classpath.

My question is : How does log4j work properly and pickup the configuration?

Ozgen
  • 1,072
  • 10
  • 19

1 Answers1

0

You say that you used log4.properties so I will be assuming you are using log4j 1.2.x (log4 2 use log4j2.properties)

Log4 perform default initialization when log4j classes are loaded into memory within the static initializer of the LogManager class.
See the section: Default Initialization Procedure in the manual

As soon as you dropped log4j.properties into your classpath it trigger log4j logging.
This procedure will be executed in any environment (tomcat container or other).
if you want to skip this procedure please note item 1 in the procedure:

Setting the log4j.defaultInitOverride system property to any other value then "false" will cause log4j to skip the default initialization procedure (this procedure).

Log4Web is an extension for depending on log4j 2 so It's irrelevant in your case.

sl4j-api.jar and sl4j-jcl.jar requires log4j-over-slf4j if you what to migrate existing code to use SLF4J without changing the code itself. If you are not interest in such migration you may ignore them.

Community
  • 1
  • 1
Haim Raman
  • 11,508
  • 6
  • 44
  • 70