I have problem configure log4j properties.
I used to use code to configure logger.
But, now I am getting the no appenders could be found WARN from groovyx.net.http.RESTClient which I can't change the code. The WARN is below:
log4j:WARN No appenders could be found for logger (groovyx.net.http.RESTClient).
log4j:WARN Please initialize the log4j system properly.
So I tried to use the log4j.properties file by default to setup the appenders. But, I don't know where I should put the log4j.properties file. I add the -Dlog4j.debug as JVM option and run the test. I am getting the below information:
log4j: Trying to find [log4j.xml] using context classloader sun.misc.Launcher$AppClassLoader@a6eb38a.
log4j: Trying to find [log4j.xml] using sun.misc.Launcher$AppClassLoader@a6eb38a class loader.
log4j: Trying to find [log4j.xml] using ClassLoader.getSystemResource().
log4j: Trying to find [log4j.properties] using context classloader sun.misc.Launcher$AppClassLoader@a6eb38a.
log4j: Trying to find [log4j.properties] using sun.misc.Launcher$AppClassLoader@a6eb38a class loader.
log4j: Trying to find [log4j.properties] using ClassLoader.getSystemResource().
log4j: Could not find resource: [null].
I am using IntelliJ and running a Spock test. Any answer will be appreciate. Thank you.
Configuring Log4J 2 Using the Properties File 1 Log4J2PropertiesConf.java. To test the Log4J2PropertiesConf class above, we will write a JUnit test class. 2 Log4J2PropertiesConfTest.java. We will now configure Log4J 2 using a properties file. ... 3 log4j2.properties. ...
Crunchify Java and J2EE Tutorials Java: How to configure log4j.properties correctly – log4j Sample ... In Java Project, with log4j it is possible to enable logging at runtime without modifying the application binary. The log4j package is designed so that these statements can remain in shipped code without incurring a heavy performance cost.
The Property Name column contains the name used in properties files and system properties; Environemt Variable for the equivalent environment variable; and Legacy Property Name for the pre-2.10 name. Path to an Log4j 2 configuration file. May also contain a comma separated list of configuration file names. May contain a URL.
In intellij, you can assign a path to the configuration file as follows: Click on the plus sign to add a path to your properties/xml file. You can add an alias for this configuration. Apply. To check if your log4j config file has been loaded, you can add the VM Option under run/edit configuration as -Dlog4j.debug.
Your log4j config file should be placed in source root.
In IDEA it may be resource folder.
Look at: Where should I put the log4j.properties file?
For Groovy it all the same.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With