TEL:400-8793-956
当前位置:开发工具

Linux上的Spring MVC项目的log4j文件未输出异常

提问者: 近期获赞: 浏览人数: 发布时间:2021-01-22 13:39:00

 问:本地测试可以打印错误日志,但是在Linux上,错误日志只会自动创建,但是没有内容。调试日志仅包含启用了Tomcat的信息,并且在项目运行时内容不会增加。

 
Log4j configuration code
<?xml version="1.0" encoding="UTF-8"?>    
<configuration status="ERROR">  
<! -- define all Appenders first -- >  
    <appenders>  
<! -- configuration of this output console -- >  
        <Console name="Console" target="SYSTEM_OUT">  
<! -- the console only outputs level and above information (onmatch), and other direct rejections (onmismatch) - >  
            <ThresholdFilter level="DEBUG" onMatch="ACCEPT" onMismatch="DENY"/>  
<! -- this is known to be the format of the output log -- >  
            <PatternLayout pattern="%d{HH:mm:ss.SSS} %-5level %class{36} %L %M - %msg%xEx%n"/>  
        </Console>  
 
<! -- the file will print out all the information. The log will be cleared automatically every time the program runs. It is determined by the append attribute. This is also very useful. It is suitable for temporary testing -- >  
<! -- if append is true, the message will be added to the specified file. If false, the message will cover the specified file. The default value is true -- >  
        <File name="log" fileName="/root/log/test.log" append="false">  
            <PatternLayout pattern="%d{HH:mm:ss.SSS} %-5level %class{36} %L %M - %msg%xEx%n"/>  
        </File>  
 
<! -- add a filter threshold filter to selectively output a category above a certain level. Onmatch = "accept" onmismatch = "deny" means to accept the match, otherwise it will be rejected -- >  
        <File name="ERROR" fileName="/root/log/log.log">  
            <ThresholdFilter level="ERROR" onMatch="ACCEPT" onMismatch="DENY"/>  
            <PatternLayout pattern="%d{yyyy.MM.dd 'at' HH:mm:ss z} %-5level %class{36} %L %M - %msg%xEx%n"/>  
        </File>  
 
<! -- this will print out all the information. Every time the size exceeds the size, the log of the size will be automatically saved under the folder created by year month and compressed as an archive -- >  
        <RollingFile name="RollingFile" fileName="/root/log/web.log"  
                     filePattern="logs/$${date:yyyy-MM}/web-%d{MM-dd-yyyy}-%i.log.gz">  
            <PatternLayout pattern="%d{yyyy-MM-dd 'at' HH:mm:ss z} %-5level %class{36} %L %M - %msg%xEx%n"/>  
            <SizeBasedTriggeringPolicy size="2MB"/>  
        </RollingFile>  
    </appenders>  
 
<! -- then define a logger. Only when a logger is defined and an appender is introduced, the appender will take effect -- >  
    <loggers>  
<! -- create a default root logger -- >  
        <root level="trace">  
            <appender-ref ref="RollingFile"/>  
            <appender-ref ref="Console"/>  
            <appender-ref ref="ERROR" />  
            <appender-ref ref="log"/>  
        </root>  
 
    </loggers>  
</configuration>  
//
web.xml Configuration
   <listener>
         <listener-class>org.apache.logging.log4j.web.Log4jServletContextListener</listener-class>
    </listener>
     <filter>
         <filter-name>log4jServletFilter</filter-name>
         <filter-class>org.apache.logging.log4j.web.Log4jServletFilter</filter-class>
     </filter>
     <filter-mapping>
         <filter-name>log4jServletFilter</filter-name>
         <url-pattern>/*</url-pattern>
         <dispatcher>REQUEST</dispatcher>
         <dispatcher>FORWARD</dispatcher>
         <dispatcher>INCLUDE</dispatcher>
         <dispatcher>ERROR</dispatcher>
     </filter-mapping>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
 
答:您可以尝试将其
<configuration status="ERROR">
更改为。
<configuration status="DEBUG">
更多有关log4j配置的信息将输出到命令行
上一篇: Android登录界面的布局
下一篇: 无法登录SVN仓库,表明DNS找不到主机地址