Logback FileAppender-日志文件为空? [英] Logback FileAppender - logfile is empty?
问题描述
在一个项目中,我在类路径上具有以下内容:
In a project I have the following on the classpath:
Bundle-ClassPath: .,
lib/logback-classic.jar,
lib/logback-core.jar,
lib/slf4j-api.jar
以及build.properties中的以下内容:
and the following in the build.properties:
bin.includes = META-INF/,\
.,\
plugin.xml,\
lib/logback-classic.jar,\
lib/logback-core.jar,\
lib/slf4j-api.jar,\
logback.xml
在根目录下,我还有一个logback.xml文件,其中包含:
In the root I also have a logback.xml file containing:
<!-- <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> -->
<!-- <layout class="ch.qos.logback.classic.PatternLayout"> -->
<!-- <Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n -->
<!-- </Pattern> -->
<!-- </layout> -->
<!-- </appender> -->
<root level="debug">
<appender-ref ref="STDOUT" />
</root>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<File>logs\\logfile.log</File>
<Append>true</Append>
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n
</Pattern>
</layout>
</appender>
</configuration>
在启动时执行的类中,我有:
In a class that gets executed at startup I have:
private static final Logger logger = LoggerFactory.getLogger(Application.class.getName());
public Object start(IApplicationContext context) {
logger.debug("debug string");
logger.warn("warn string");
logger.error("error string");
构建并运行应用程序时,会在应用程序的根目录中创建一个logs \ logfile.log文件,但该文件为空.如果我使用ConsoleAppender并启用了控制台,则可以正常工作.
When I build and run my application a file logs\logfile.log is created in the root of my application but its empty. If I use the ConsoleAppender and enable the console it works fine.
为什么使用FileAppender时logback不会写到日志文件?
Why does logback not write to the logfile when using the FileAppender?
推荐答案
您是否尝试过将文件appender-ref添加到logback.xml的根目录中,如下所示:
Have you tried with adding file appender-ref to root in logback.xml as shown below:
<root level="debug">
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />
</root>
这篇关于Logback FileAppender-日志文件为空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!