简体   繁体   English

Tomcat和SLF4J-未将日志写入文件

[英]Tomcat and SLF4J - not writing log to file

I am trying to implement a logging trail for my app using slf4j-log4j12. 我正在尝试使用slf4j-log4j12为我的应用程序实现日志记录跟踪。 I've configured everything and it worked fine while i was testing it in standalone mode. 我已经配置了所有内容,并且在独立模式下对其进行测试时效果很好。 Now that i had deployed it in tomcat, it stopped working! 现在,我已将其部署在tomcat中,它停止工作了! It simply prints the log (even the one i create with slf4j) in the console, but not in the file! 它只是在控制台中打印日志(甚至是我用slf4j创建的日志),但不在文件中打印!

Here is my log4j.xml: 这是我的log4j.xml:

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
    <appender name="fileAppender" class="org.apache.log4j.RollingFileAppender">
        <param name="Threshold" value="INFO" />
        <param name="File" value="assp.log" />
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d  %-5p  [%c{1}] %m %n" />
        </layout>
    </appender>

    <appender name="console" class="org.apache.log4j.ConsoleAppender">
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d %-5p %c{1} - %m%n" />
        </layout>
    </appender>

    <root>
        <priority value="debug" />
        <appender-ref ref="fileAppender" />
        <appender-ref ref="console" />
    </root>
</log4j:configuration>

My dependencies: 我的依赖:

<dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jul-to-slf4j</artifactId>
            <version>${slf4j.version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
            <version>${slf4j.version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${slf4j.version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>${slf4j.version}</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>${log4j.version}</version>
        </dependency>

And here is my testing class 这是我的测试课

private Logger LOGGER = LoggerFactory.getLogger(Test.class);
@RequestMapping("*")
public String root(RedirectAttributes redirectAttributes){
    LOGGER.info("{} - entering root page. Redirecting to index.", System.currentTimeMillis());
    return "redirect:/index";
}

Output (in console): 输出(在控制台中):

INFO 1404999952210 - entering root page. Redirecting to index.

Can someone please help? 有人可以帮忙吗? Thanks 谢谢

After a while i solve the problem. 一段时间后,我解决了这个问题。 I follow the apache documentation Here - Using LOG4J 我在这里遵循apache文档-使用LOG4J

Hope this helps anyone with the same problem i had. 希望这对遇到同样问题的人有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM