如何禁用Java ortools CP求解器日志记录?

时间:2019-06-03 10:56:53

标签: scala logging log4j constraint-programming or-tools

上下文:我正在使用Java或工具解决CP问题(来自约束求解程序包)     问题:我想使这些打印件/日志消失。他们看起来像这样:

[11:29:43] ./ortools/constraint_solver/search.cc:240: Start search (memory used = 5,28 GB)
[11:29:43] ./ortools/constraint_solver/search.cc:240: Start search (memory used = 5,28 GB)
[11:29:43] ./ortools/constraint_solver/search.cc:240: End search (time = 2 ms, branches = 0, failures = 1, memory used = 5,28 GB, speed = 0 branches/s)
[11:29:43] ./ortools/constraint_solver/search.cc:240: End search (time = 3 ms, branches = 0, failures = 1, memory used = 5,28 GB, speed = 0 branches/s)
[11:29:43] ./ortools/constraint_solver/search.cc:240: Start search (memory used = 5,28 GB)

尽管这是我的log4j2.xml文件:

<configuration status="OFF">
    <appenders>
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout pattern="[%d{yyyy.MM.dd HH:mm:ss.SSS}][%t] [%-5level] [%logger{36}] - %msg%n%xException"/>
        </Console>

        <RollingFile name="RollingFile" fileName="./../../logs/raptor-engine-tests.log" filePattern="./../../logs/raptor-engine-tests-%d{MM-dd-yyyy}.log.gz" ignoreExceptions="false">
            <PatternLayout pattern="[%d{yyyy.MM.dd HH:mm:ss.SSS}][%t] [%-5level] [%logger{36}] - %msg%n%xException"/>
            <TimeBasedTriggeringPolicy/>
        </RollingFile>
    </appenders>

    <loggers>
        <logger name="akka" level="info"/>
        <Logger name="org.hibernate" level="info"/>
        <Logger name="com.google.ortools" level="info"/>

        <!-- levels: trace, debug, info, warn, error, fatal -->
        <root level="info">
            <appender-ref ref="Console"/>
            <appender-ref ref="RollingFile"/>
        </root>
    </loggers>

</configuration>

有人遇到这个问题吗?您是如何解决的?就像完全忽略了“ com.google.ortools”记录器一样。

2 个答案:

答案 0 :(得分:3)

您在使用路由库吗?还是直接使用CP解算器?

在第一种情况下,应该有一个参数来控制日志记录:https://github.com/google/or-tools/blob/f3fd201e68cf75b7720ff5c3cadc599a1d02b54b/ortools/constraint_solver/routing_parameters.proto#L376

在第二种情况下,只有在创建搜索日志对象并在搜索时使用它时,才会发生这种情况。

现在,这些日志由C ++代码生成,因此记录器将不执行任何操作。

答案 1 :(得分:1)

谢谢!您解决了我的问题!看起来像这样:

//      // Search log
val kLogFrequency = 1000000
val searchLog     = makeSearchLog(kLogFrequency, objectiveMonitor)

我在Scala工作。非常感谢您的帮助!