在Eclipse中配置Logback [英] Configuring Logback in Eclipse

查看:854
本文介绍了在Eclipse中配置Logback的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从Log4j切换到Logback,但是在使Logback正常工作方面还没有成功.我已经将logback.xml放置在我的Eclipse Java项目的根目录中,下面是其内容:

I'm in the process of switching from Log4j to Logback but I'm not having success at making Logback work yet. I have placed logback.xml in the root directory of my Eclipse Java project and below is its content:

<configuration>

  <appender name="FILE" class="ch.qos.logback.core.FileAppender">
    <file>myApp.log</file>

    <encoder>
      <pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern>
    </encoder>
  </appender>

  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
      <pattern>%msg%n</pattern>
    </encoder>
  </appender>

  <root level="debug">
    <appender-ref ref="FILE" />
    <appender-ref ref="STDOUT" />
  </root>
</configuration>

以下是我的Main.java的相关内容:

And below is the relevant content of my Main.java:

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Main
{
  static final Logger logger = LoggerFactory.getLogger(Main.class);

  public static void main(String[] args)
  {
    logger.info("Main started");
  }
}

这似乎不起作用,因为在我的Eclipse Java应用程序的根目录中没有创建名为myApp.log的文件.知道我在做什么错吗?

This does not seem to be working as no file named myApp.log is created in the root of my Eclipse Java application. Any idea what I'm doing wrong?

推荐答案

配置文件必须位于类路径上.我的猜测是不是.检查项目的构建路径.

The configuration file needs to be on the classpath. My guess is that it isn't. Check the build path for the project.

这篇关于在Eclipse中配置Logback的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆