Search code examples
logginglog4j2logbackoptaplanner

Can I change OptaPlanner's logging level when using it as a local project dependency?


I have a project in Eclipse which uses OptaPlanner (v8.12.0). I want to be able to write temporary debug statements within the OptaPlanner code itself, so I:

  1. cloned the repo,
  2. checked out branch 8.12.x,
  3. built using mvn,
  4. imported as a pre-existing Maven project optaplanner-core (again, Eclipse), and
  5. removed the optaplanner-core dependency from my Gradle dependencies

Everything compiles and runs just fine, but OptaPlanner no longer responds to my log config changes.

We're using Log4j2 and, when pulling OptaPlanner using the standard build process (Gradle), I can set the log level just fine using the Log4j2 config. But, with the src as a project dependency, it's not working.

I have tried:

  • Including a local logback.xml
  • Adding adding as a vm arg: -Dlogging.level.org.optaplanner=trace
  • Adding adding as a vm arg: -Dlog4j.configurationFile=C:\path\to\log4j2.xml
  • Setting an environment variable LOGGING_CONFIG=C:\path\to\logback.xml
  • Setting the level programmatically using Configurator

Solution

  • OptaPlanner only has Logback as a scoped-to-test dependency.

    To get a local copy of OptaPlanner to pick up your log config, you need to (locally) add your logging dependency to the OptaPlanner buildpath.

    For me, this meant adding a Log4j2 dependency to the OptaPlanner pom.xml:

        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-slf4j-impl</artifactId>
            <version>pick.your.favorite</version>
        </dependency>
    

    I also deleted the scoped test dependency just to be sure it wouldn't screw with anything.

    I suspect, for those not using a dependency management tool, that you could manually add a JAR to the buildpath.