RSS Feed Subscribe to RSS Feed


Add log4j logging for a unit test in IntelliJ

In IntelliJ

  • Click: Run -> Edit Configuration
  • Select your test configuration (or add a new one)
  • In VM parameters, add
    (Or wherever your log4j properties file is)

That’s it. The test should now run with log4j logging (although obviously you need to have the necessary log4j jars available).
This example uses a windows file format, but will work equally well with *nix.

I use this approach for turning on MyBatis logging for individual tests. See here for a basic setup of a log4j.xml file to enable logging with MyBatis.

Tags: , , , ,

2 Responses to “Add log4j logging for a unit test in IntelliJ”

  1. Franz |

    You can also add a file at the root of your test packages.
    In this case all your tests use this configuration and you don’t need to edit all your run config.

  2. admin |

    Hey Franz,
    Thanks for the info.
    I prefer to turn on logging on a case by case basis for MyBatis (typically when I’m debugging), since the logging is verbose. But you’re right of course, logging can be turned on for all tests.

    I often refer to this when trying to figure out where to place the log4j config file…

Leave a Reply