我想调试springframework,知道在Restcontroller中路由请求时发生了什么。
我已经定义了如下所示的 JSON 配置,但这对我不起作用。
{
"configuration": {
"appenders": {
"Console": {
"name": "consoleAppender",
"target":"SYSTEM_OUT",
"PatternLayout": {
"pattern": "%d{yyyy-MM-dd HH:mm:ss:SSS} %-5p [%c{1}:%t]:%L - %m%n"
}
}
},
"loggers": {
"root": {
"level": "info",
"appender-ref": [{ "ref": "consoleAppender" }]
},
"logger":[{
"name":"org.springframework",
"level": "debug",
"appender-ref": [{ "ref": "consoleAppender" }]
}]
}
}
}
如果我在这里做错了,请告诉我
另一个问题是,使用JSON或XML配置log4j的正确方法是什么?
答案 0 :(得分:1)
以下配置用于log4j框架。它描述了XML。
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="SYSLOG" class="org.apache.log4j.net.SyslogAppender">
<param name="Facility" value="LOCAL0"/>
<param name="FacilityPrinting" value="false"/>
<param name="SyslogHost" value="localhost"/>
<param name="Threshold" value="INFO"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ISO8601} %-5p [WhereRU][%t|%c{1}] %L %M %m\n"/>
</layout>
</appender>
<appender name="SERVER_DEBUG" class="org.apache.log4j.DailyRollingFileAppender">
<param name="DatePattern" value="'-'yyyy-MM-dd'.log'"/>
<param name="File" value="/var/log/testing/testing-debug"/>
<param name="Threshold" value="DEBUG"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ISO8601} %-5p [WhereRU][%t|%c{1}] %L %M %m\n"/>
</layout>
</appender>
<appender name="SERVER_ERROR" class="org.apache.log4j.DailyRollingFileAppender">
<param name="DatePattern" value="'-'yyyy-MM-dd'.log'"/>
<param name="File" value="/var/log/testing/testing-error"/>
<param name="Threshold" value="ERROR"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ISO8601} %-5p [WhereRU][%t|%c{1}] %L %M %m\n"/>
</layout>
</appender>
<appender name="STDOUT" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ISO8601} %-5p [WhereRU][%t|%c{1}] %L %M %m\n" />
</layout>
</appender>
<logger name="com.testing" additivity="false">
<level value="DEBUG"/>
<appender-ref ref="SYSLOG"/>
<appender-ref ref="SERVER_DEBUG"/>
<appender-ref ref="SERVER_ERROR"/>
<appender-ref ref="STDOUT" />
</logger>
<logger name="org.springframework" additivity="false">
<level value="ERROR"/>
<appender-ref ref="SERVER_ERROR"/>
</logger>
<logger name="org.apache" additivity="false">
<level value="ERROR"/>
<appender-ref ref="SERVER_ERROR"/>
</logger>
<logger name="org.springframework.integration">
<level value="info" />
</logger>
<logger name="org.springframework.integration.samples">
<level value="info" />
</logger>
<!-- Everything else to catalina.out -->
<root>
<level value="ERROR"/>
<appender-ref ref="STDOUT" />
<appender-ref ref="SERVER_DEBUG" />
<appender-ref ref="SERVER_ERROR" />
</root>
</log4j:configuration>
希望这些东西能解决你的问题。