如何在不是Spring Boot应用程序的Spring应用程序中激活spring的内部日志记录

时间:2019-02-11 14:53:53

标签: spring logging log4j

在春季的源代码中,我看到:

(above code) %>% pull(description) %>% paste(collapse = ",")

[1] "('a', 2, '2019-02-11 09:52:14'),('b', 3, '2019-02-11 09:52:14')"

我该怎么做才能使sel = [item for item in myl if "SELECT" in item] print sel ['(SELECT total_marks\n'] 为真?

使用Spring Boot,如果我添加属性boolean debug = logger.isDebugEnabled(); ,它将起作用。但不是在春季。

1 个答案:

答案 0 :(得分:0)

在springboot 2.1.9.RELEASE上测试

  1. 直接在配置文件application.yml中设置根日志级别
logging:
  level:
    root: trace
  1. 在maven项目的资源目录下创建文件“ logback.xml”。
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="true" scan="false" scanPeriod="1 seconds">
    <appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d [%thread] %-5level %logger{36} [%file : %line] - %msg%n</pattern>
        </encoder>
    </appender>
    <root level="trace">
        <appender-ref ref="stdout"/>
    </root>
</configuration>

配置中的

debug="true"将输出许多有用的调试日志,例如

10:02:15,511 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [file:/C:/Users/win/proj/my_web/manage/target/classes/logback.xml]
10:02:15,909 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to TRACE
10:02:15,909 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [stdout] to Logger[ROOT]

如果在输出Propagating下方看到,则表示您在某处具有配置日志级别,例如logging.level.root=info中的application.properties

10:02:17,026 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@495b0487 - Propagating INFO level on Logger[ROOT] onto the JUL framework