Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JBoss Logging for Java Unit Test?

I've inherited some java code that uses the JBoss Logging implementation explicitly. I know that this is normally configured as a JBoss Subsytem, and I'm able to observe various log tuning operations just fine when running on the server. However, I'm not getting any log message output for unit tests. I've dropped several configuration files on the test classpath to include:

  • logging.properties
  • log4j.xml
  • log4j2.xml

but have not seen any results. Has anyone been able to configure the JBoss Logging system such that they're visible outside of the container in unit tests? Is this even possible? The logging configuration guide didn't speak to how to do this.

like image 718
josh-cain Avatar asked Nov 22 '22 03:11

josh-cain


1 Answers

You can make log4j.xml work, but you need to make sure that you have a compatible vanilla log4j version on the test classpath, e.g. 1.2.17, and that you don't have the modified version, log4j-jboss-logmanager, on the the classpath, which doesn't read log4j.xml.

Details.

See https://stackoverflow.com/a/18323126/1341535. I take this:

I would recommend you configure the log manager using the logging subsystem provided with the application server. This is the only way to configure the server logging.

to imply that it's basically impossible to configure the JBoss Log Manager in tests, because there is no server subsystem configuration and nothing to parse it. Maybe you could configure it programmatically, but that's too inconvenient.

So this leaves us using the JBoss Logging facade with log4j for the log manager, which can be easily configured with log4j.xml.

Now, that I think of it, there is a logging.properties file in Wildfly, that configures logging before the logging subsystem is initialized. That means you can configure the JBoss Log Manager with logging.properties, you just need to put the relevant jars on the test classpath, probably jboss-logmanager and log4j-jboss-logmanager.

like image 135
Vsevolod Golovanov Avatar answered Jan 16 '23 06:01

Vsevolod Golovanov