如何关闭optaplanner中的日志记录?

时间:2015-03-19 10:48:01

标签: optaplanner

我只是想关闭日志记录。我在文档中找到了这个: https://docs.jboss.org/optaplanner/release/6.2.0.Final/optaplanner-docs/html_single/index.html#logging

但是,我的项目没有logback.xml文件。

有什么建议吗?

修改

我现在已将以下logback.xml文件添加到类路径的根目录中:

<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false">

  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <!-- encoders are assigned the type
         ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
    <encoder>
      <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
    </encoder>
  </appender>

  <root level="warn">
    <appender-ref ref="STDOUT" />
  </root>
</configuration>

这些jar文件在我的类路径中:

  • ANTLR运行时-3.5.jar
  • 公地编解码器-1.4.jar
  • 公地-IO-2.1.jar
  • 公地琅2.6.jar
  • 公地math3-3.2.jar
  • DOM4J-1.6.1.jar
  • 滴料编译-6.2.0.Final.jar
  • 滴料芯-6.2.0.Final.jar
  • 滴料-decisiontables-6.2.0.Final.jar
  • 滴料的模板-6.2.0.Final.jar
  • ECJ-4.3.1.jar
  • 的freemarker-2.3.19.jar
  • 番石榴13.0.1.jar
  • jacop-4.2.0.jar
  • jcommon-1.0.23.jar
  • jfreechart的-1.0.19.jar
  • jgrapht核-0.9.1-SNAPSHOT.jar
  • 纪伊-API-6.2.0.Final.jar
  • 纪伊内部-6.2.0.Final.jar
  • 的logback-经典1.0.9.jar
  • 的logback核-1.0.9.jar
  • mvel2-2.2.4.Final.jar
  • optaplanner-基准-6.2.0.Final.jar
  • optaplanner核-6.2.0.Final.jar
  • POI-3.10.1.jar
  • POI-OOXML-3.10.1.jar
  • POI-OOXML-架构 - 3.10.1.jar
  • 的protobuf-java的2.5.0.jar
  • SLF4J-API-1.7.2.jar
  • STAX-API-1.0.1.jar
  • XML的API-1.3.04.jar
  • 的xmlbeans-2.3.0.jar
  • xmlpull-1.1.3.1.jar
  • xpp3_min-1.1.4c.jar
  • 的XStream-1.4.7.jar

这些是日志消息:

12:33:09.729 [main] DEBUG o.o.c.i.l.DefaultLocalSearchPhase -     LS step (47), time spent (4230), score (-452), new best score (-452), accepted/selected move count (1000/1043), picked move (gc.Vertex@36bc2602 => 170).
12:33:09.808 [main] DEBUG o.o.c.i.l.DefaultLocalSearchPhase -     LS step (48), time spent (4309), score (-447), new best score (-447), accepted/selected move count (1000/1035), picked move (gc.Vertex@265753b0 => 169).
12:33:09.887 [main] DEBUG o.o.c.i.l.DefaultLocalSearchPhase -     LS step (49), time spent (4388), score (-442), new best score (-442), accepted/selected move count (1000/1042), picked move (gc.Vertex@70dc77a8 => 169).
12:33:09.968 [main] DEBUG o.o.c.i.l.DefaultLocalSearchPhase -     LS step (50), time spent (4469), score (-437), new best score (-437), accepted/selected move count (1000/1052), picked move (gc.Vertex@47f128ad => 106).
12:33:10.048 [main] DEBUG o.o.c.i.l.DefaultLocalSearchPhase -     LS step (51), time spent (4549), score (-432), new best score (-432), accepted/selected move count (1000/1045), picked move (gc.Vertex@2abbb9f2 => 229).
12:33:10.127 [main] DEBUG o.o.c.i.l.DefaultLocalSearchPhase -     LS step (52), time spent (4628), score (-427), new best score (-427), accepted/selected move count (1000/1034), picked move (gc.Vertex@2db68692 => 234).
12:33:10.208 [main] DEBUG o.o.c.i.l.DefaultLocalSearchPhase -     LS step (53), time spent (4709), score (-422), new best score (-422), accepted/selected move count (1000/1054), picked move (gc.Vertex@fa3582a => 129).
12:33:10.286 [main] DEBUG o.o.c.i.l.DefaultLocalSearchPhase -     LS step (54), time spent (4787), score (-417), new best score (-417), accepted/selected move count (1000/1046), picked move (gc.Vertex@56f3b98c => 137).
12:33:10.365 [main] DEBUG o.o.c.i.l.DefaultLocalSearchPhase -     LS step (55), time spent (4866), score (-412), new best score (-412), accepted/selected move count (1000/1044), picked move (gc.Vertex@7e25a483 => 170).
12:33:10.441 [main] DEBUG o.o.c.i.l.DefaultLocalSearchPhase -     LS step (56), time spent (4942), score (-407), new best score (-407), accepted/selected move count (1000/1042), picked move (gc.Vertex@330d8014 => 127).
12:33:10.519 [main] DEBUG o.o.c.i.l.DefaultLocalSearchPhase -     LS step (57), time spent (5020), score (-402), new best score (-402), accepted/selected move count (1000/1048), picked move (gc.Vertex@c911382 => 195).
12:33:10.598 [main] DEBUG o.o.c.i.l.DefaultLocalSearchPhase -     LS step (58), time spent (5099), score (-397), new best score (-397), accepted/selected move count (1000/1036), picked move (gc.Vertex@7349c1f6 => 189).
12:33:10.677 [main] DEBUG o.o.c.i.l.DefaultLocalSearchPhase -     LS step (59), time spent (5178), score (-392), new best score (-392), accepted/selected move count (1000/1055), picked move (gc.Vertex@2aab8eb6 => 234).
12:33:10.755 [main] DEBUG o.o.c.i.l.DefaultLocalSearchPhase -     LS step (60), time spent (5256), score (-389), new best score (-389), accepted/selected move count (1000/1049), picked move (gc.Vertex@7d19367b => 137).

2 个答案:

答案 0 :(得分:1)

查看类路径以查看您使用的日志记录实现。取决于你在那里找到的东西:

  • logback-classic.jar:添加logback.xml并将所有内容设置为日志级别WARN
  • log4j.jar:添加log4j.xml(或属性)并将所有内容设置为日志级别WARN

如果您只是看到slf4j-api,那么您可能想要添加一个slf4j-noop或其他东西。如果您看到slf4j-over-X,那么您将要将X配置为仅记录级别WARN。

答案 1 :(得分:1)

我现在通过在我的代码中添加以下两行来解决问题:

LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
loggerContext.stop();