1

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
Ryan Moser
  • 123
  • 1
  • 12
  • Something here confuses me. You say you use Log4J2. Yet you provide configuration for Logback? – Lukáš Petrovický Jan 27 '22 at 23:03
  • 1
    @LukášPetrovický I thought that OptaPlanner used Logback internally, so I wanted to see if I could get a config picked up. I double checked and I was mistaken. Everything goes through SLF4J (as I'm sure you are aware). – Ryan Moser Jan 28 '22 at 00:25
  • To be clear, my project has a Log4j2 config and I myself have a custom one that I use. Neither were being picked up. – Ryan Moser Jan 28 '22 at 00:26

1 Answers1

3

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.

Ryan Moser
  • 123
  • 1
  • 12
  • 1
    For more info on how/why to enable/configure logging, see https://www.optaplanner.org/docs/optaplanner/latest/planner-configuration/planner-configuration.html#logging – Geoffrey De Smet Feb 01 '22 at 16:52