Using Maven build system under eclipse.
I have just switched by project from using Apache Commons Logging to Java Utils Logging, as it has to live in an environment where Java Utils Logging is the main logger (Google App Engine), and other libraries that I use already use it (Restlet). One of the features I like in eclipse is to be able right click on a function thats marked with @test and select "Run as Junit Test". When I do this now, I see no logging output. I have created a file
src/test/java/resources/logging.properties
handlers = java.util.logging.ConsoleHandler
.level=INFO
my.great.package.level=FINE
java.util.logging.ConsoleHandler.level = FINE
But still I see nothing when running test inside Eclipse. Before it used to all work beautifully with commons logging and log4j. What am I doing wrong?
Thanks in advance,
Basically, you create your own Appender and add it to the logger you want. If you'd want to collect everything, the root logger is a good place to start, but you can use a more specific if you'd like. Don't forget to remove the Appender when you're done, otherwise you might create a memory leak.
properties goes in the directory src/main/resources . My test version goes in src/test/resources . The Eclipse build path (classpath) is set up to search src/test/resources before src/main/resources , so your unit tests use the test file. The JAR (or WAR) build instructions use the files from src/main/resources .
If you right click in Project Explorer and choose New, you see a much shorter menu that doesn't include the Junit option. Needs to be done in Package Explorer view...
I'm not sure if Java Logging can auto-detect configuration files in the same way that log4j
can.
Have you tried specifying where the configuration file is for the test runner, e.g.:
-Djava.util.logging.config.file=path/to/logging.properties
You can add this to the system properties via the VM Arguments text box in the Eclipse Run Configurations dialog.
You can also configure the maven-surefire-plugin
with the same system property so you get logging during your build - if desired.
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