【问题标题】:IntelliJ scala worksheet: Reduce debug loggingIntelliJ scala 工作表:减少调试日志记录
【发布时间】:2016-04-30 08:52:59
【问题描述】:

将工作表与 Slick 一起使用时,它会记录很多调试信息,以至于我看不到我正在做的事情的实际结果。几个小时以来,我一直在尝试弄清楚如何禁用调试日志记录,但我无法弄清楚。

如何禁用(光滑)/(工作表)日志记录?

来自工作表:

  db.run(
    countries.take(5)
      .map(_.country)
      .result
  )

输出约 200 行:

countries: slick.lifted.TableQuery[Country] = Rep(TableExpansion)
z: slick.lifted.Query[Country,Country#TableElementType,Seq] = Rep(Filter @968224334)
res0: java.sql.Connection = org.postgresql.jdbc4.Jdbc4Connection@40d24bbd
BEFORE
22:17:58.192 [NGSession 241: 127.0.0.1: compile-server] DEBUG slick.compiler.QueryCompiler - Source:
| Bind
|   from s2: Take
|     from: TableExpansion
|       table s3: Table country
|       columns: ProductNode
|         1: Path s3.id : String'
|         2: Path s3.name : String'
|     count: LiteralNode 5 (volatileHint=false)
|   select: Pure t4
|     value: Path s2.name : String'

22:17:58.193 [NGSession 241: 127.0.0.1: compile-server] DEBUG slick.compiler.AssignUniqueSymbols - Detected features: UsedFeatures(false,false,false,false)
22:17:58.194 [NGSession 241: 127.0.0.1: compile-server] DEBUG slick.compiler.QueryCompiler - After phase assignUniqueSymbols:
| Bind
|   from s5: Take
|     from: TableExpansion
|       table s6: Table country
|       columns: ProductNode
|         1: Path s6.id : String'
|         2: Path s6.name : String'
|     count: LiteralNode 5 (volatileHint=false)
|   select: Pure t8
|     value: Path s5.name : String'

22:17:58.195 [NGSession 241: 127.0.0.1: compile-server] DEBUG slick.compiler.QueryCompiler - After phase inferTypes: (no change)
22:17:58.196 [NGSession 241: 127.0.0.1: compile-server] DEBUG slick.compiler.ExpandTables - Found Selects for NominalTypes: @t7
22:17:58.197 [NGSession 241: 127.0.0.1: compile-server] DEBUG slick.compiler.ExpandTables - With correct table types:
| Bind : Vector[t8<String'>]
|   from s5: Take : Vector[@t7<{id: String', name: String'}>]
|     from: Table country : Vector[@t7<{id: String', name: String'}>]
|     count: LiteralNode 5 (volatileHint=false) : Long
|   select: Pure t8 : Vector[t8<String'>]
|     value: Path s5.name : String'

22:17:58.197 [NGSession 241: 127.0.0.1: compile-server] DEBUG slick.compiler.ExpandTables - Table expansions: @t7 -> (s6,ProductNode)
22:17:58.198 [NGSession 241: 127.0.0.1: compile-server] DEBUG slick.compiler.QueryCompiler - After phase expandTables:
| Bind : Vector[t8<String'>]
|   from s5: Take : Vector[@t7<{id: String', name: String'}>]
|     from: Table country : Vector[@t7<{id: String', name: String'}>]
|     count: LiteralNode 5 (volatileHint=false) : Long
|   select: Pure t8 : Vector[t8<String'>]
|     value: Path s5.name : String'

22:17:58.199 [NGSession 241: 127.0.0.1: compile-server] DEBUG slick.compiler.QueryCompiler - After phase forceOuterBinds:
| Bind : Vector[t8<String'>]
|   from s5: Take : Vector[@t7<{id: String', name: String'}>]
|     from: Table country : Vector[@t7<{id: String', name: String'}>]
|     count: LiteralNode 5 (volatileHint=false) : Long
|   select: Pure t8 : Vector[t8<String'>]
|     value: Path s5.name : String'

22:17:58.200 [NGSession 241: 127.0.0.1: compile-server] DEBUG slick.compiler.QueryCompiler - After phase removeMappedTypes: (no change)
22:17:58.200 [NGSession 241: 127.0.0.1: compile-server] DEBUG slick.compiler.QueryCompiler - After phase expandSums: (no change)
22:17:58.201 [NGSession 241: 127.0.0.1: compile-server] DEBUG slick.compiler.QueryCompiler - After phase expandRecords:
| Bind : Vector[t8<String'>]
|   from s5: Take : Vector[@t7<{id: String', name: String'}>]
|     from: Table country : Vector[@t7<{id: String', name: String'}>]
|     count: LiteralNode 5 (volatileHint=false) : Long
|   select: Pure t8 : Vector[t8<String'>]
|     value: Path s5.name : String'

22:17:58.202 [NGSession 241: 127.0.0.1: compile-server] DEBUG slick.compiler.FlattenProjections - Flattening projection t8
22:17:58.202 [NGSession 241: 127.0.0.1: compile-server] DEBUG slick.compiler.FlattenProjections - Analyzing s5.name with symbols 
| Path s5.name : String'

22:17:58.203 [NGSession 241: 127.0.0.1: compile-server] DEBUG slick.compiler.FlattenProjections - Translated s5.name to:
| Path s5.name

22:17:58.203 [NGSession 241: 127.0.0.1: compile-server] DEBUG slick.compiler.FlattenProjections - Flattening node at Path 
| Path s5.name

22:17:58.204 [NGSession 241: 127.0.0.1: compile-server] DEBUG slick.compiler.FlattenProjections - Adding definition: s9 -> Path s5.name
22:17:58.204 [NGSession 241: 127.0.0.1: compile-server] DEBUG slick.compiler.FlattenProjections - Adding translation for t8: (Map(List() -> s9), UnassignedType)
22:17:58.204 [NGSession 241: 127.0.0.1: compile-server] DEBUG slick.compiler.FlattenProjections - Flattened projection to
| Pure t8
|   value: StructNode
|     s9: Path s5.name

22:17:58.205 [NGSession 241: 127.0.0.1: compile-server] DEBUG slick.compiler.QueryCompiler - After phase flattenProjections:
| Bind : Vector[t8<{s9: String'}>]
|   from s5: Take : Vector[@t7<{id: String', name: String'}>]
|     from: Table country : Vector[@t7<{id: String', name: String'}>]
|     count: LiteralNode 5 (volatileHint=false) : Long
|   select: Pure t8 : Vector[t8<{s9: String'}>]
|     value: StructNode : {s9: String'}
|       s9: Path s5.name : String'

(它会一直持续下去......)

那么我该如何关闭这个日志记录呢?

【问题讨论】:

    标签: scala intellij-idea slick


    【解决方案1】:

    假设您使用默认的sbt directory structure,您需要configure logback 来仅记录您想要的内容。为此,请添加具有以下内容的文件src/main/resources/logback.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
    
      <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
          <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
      </appender>
    
      <logger name="slick.lifted" level="INFO" />
    
      <root level="debug">
        <appender-ref ref="STDOUT" />
      </root>
    </configuration>
    

    当然,您可以配置除INFO 之外的其他日志级别,也可以为特定的 slick 包配置其他日志级别。

    最后,如果您使用的是 Playframework 目录结构,请将 logback.xml 文件放在 conf 目录中。

    【讨论】:

      【解决方案2】:

      我在使用 Spark 代码的 Scala 工作表中遇到了类似的问题,它在日志中写入了数百条 DEBUG 消息 - 全部以 [NGSession 241: 127.0.0.1: compile] DEBUG ... 开头

      该项目使用了几个模块,无论我将调整后的logback.xml文件放在哪里,它都没有被拾取。

      我注意到这个NGSession 与Scala 编译服务器有关。通过明确告诉服务器使用哪个logback.xml,它被拾取:

      添加参数...

      之后我重新启动了编译服务器(停止/启动)并且它工作了。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2023-04-10
        • 1970-01-01
        • 1970-01-01
        • 2015-01-11
        • 2011-03-26
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多