0
votes

I'm trying to configure Spring (non boot) MVC project with log4j2 logging capabilities. Currently I've placed all *.properties files in a location that is not in the class path. I've used @PropertySource annotation for this configuration. I'm getting below message

ERROR StatusLogger No Log4j 2 configuration file found.
Using default configuration (logging only errors to the console), or user programmatically provided configurations.
Set system property 'log4j2.debug' to show Log4j 2 internal initialization logging.
See https://logging.apache.org/log4j/2.x/manual/configuration.html for instructions on how to configure Log4j 2

Any clue on how and where I've done wrong? if there are good references to check please do share.

1
When you use @PropertySource, the properties files have to be in your classpath, either on your project, or on your web application server. - DamCx
@DamCx there is a way we could give an absolute path as resource locator where the properties file are located ("file:" instead of "class-path:"). I provided log4j2 .properties file the similar way but it didn't work. Other properties files that I loaded I was able to obtain the value using EL or Spring Environment interface. - StO
@DamCx I set a sysout and printed env.getProperty(<some-log4j-property-key>); a key mentioned in the log4j2.properties file. And sysout printed the value. But when I up the deployment server it gave the initially mentioned message.. - StO

1 Answers

1
votes

Add log4j2-web package into project, and then add listener on web.xml:

<listener>
    <listener-class>org.apache.logging.log4j.web.Log4jServletContextListener</listener-class>
</listener>

and you can set configure path here:

<context-param>
    <param-name>log4jConfiguration</param-name>
    <param-value>file:///D:/conf/myLogging.xml</param-value>
</context-param>