6

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.

josh-cain
  • 4,997
  • 7
  • 35
  • 55

2 Answers2

2

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.

Community
  • 1
  • 1
Vsevolod Golovanov
  • 4,068
  • 3
  • 31
  • 65
  • Sent an upvote your way, but I've actually migrated off of this code by now, so I don't have a chance to try your solution to validate! Did you test to see if it worked? Sounds solid. – josh-cain Mar 14 '17 at 21:55
  • @JoshC13, we use the "log4j.xml + vanilla log4j" approach at my job currently, it does work. – Vsevolod Golovanov Mar 15 '17 at 22:06
-1

I will try to test the code using Arquillian Test Cases, it features the possibility to deploy parts of your code only to test it in a "real environment". It is reccomended in a lot of RH JBoss documentation.

You can try reusing your junit code, and modify them using this guide: http://arquillian.org/guides/getting_started/

I'm not a guru of that technology. I hope it would help you.

  • 1
    The thing I'm really after here is the ability to use the jboss logging system *outside* of a container environment (per the question). Something like arquillian tests work fine since the JBoss logging subsystem will be initialized for the container in which the application runs. However, I would ideally like logging support for unit, rather than integration tests requiring containers and such. – josh-cain Feb 11 '16 at 14:09
  • Ok. Sorry that it appears like an answer, but I cannot comment yet ;) – Andrea Artuso Feb 11 '16 at 14:25