2

I am trying to add a custom Log4J configuration to a large software project built using IntelliJ 2016.1, but the IDE seems to completely ignore the properties file supplied (log4j.properties in plain text - not XML) in unit tests.

More specifically, running tests written against JUnit 4, IntelliJ does not show any logging messages without going to the Run | Edit configurations menu and then supplying the following argument to the VM, via the VM Options box:

  • -Dlog4j.configuration=/absolute/path/to/log4j.properties

The weird thing is that the contents of the file specified are completely ignored.

So, even if the above path is replaced by a path to a file that does not even exist, or if the path is deleted altogether, IntelliJ continues printing logging messages in the same layout as before, as if it reads the properties from a completely different location. Removing the -Dlog4j.configuration parameter, stops logging messages entirely. It's as if the IDE understands the -Dlog4j.configuration as an ON/OFF switch for logging, without caring about any path supplied with it.

There are multiple Log4J and SLF4J JARs in the project classpath and numerous log4j.properties files around, but even deleting all of the latter doesn't change the logging output. Apparently the properties file specified via -Dlog4j.configuration is ignored by Log4J all the time.

Any ideas?

PNS
  • 19,295
  • 32
  • 96
  • 143

1 Answers1

1

The solution is actually simple. Essentially, the file has to be specified as a URL, i.e. one has to supply the configuration as follows:

  • -Dlog4j.configuration=file:///absolute/path/to/log4j.properties

Apparently, the prefix file: works too, without the full URI scheme syntax file:///.

This is also described in the answers of a similar StackOverflow question.

Community
  • 1
  • 1
PNS
  • 19,295
  • 32
  • 96
  • 143