Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configuring Logback in Eclipse

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>

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");
  }
}

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?

like image 991
Arya Avatar asked Dec 29 '12 19:12

Arya


People also ask

How do you add a Logback?

Assuming you have the latest version of IntelliJ IDEA installed, no additional plugin installation is necessary. IntelliJ IDEA supports Maven out of the box. You can import logback into IDEA by selecting File→ New Project → Import from external model→ Maven, then select $LOGBACK_HOME as the Root directory.

What is Logback configuration?

Logback is one of the most widely used logging frameworks in the Java Community. It's a replacement for its predecessor, Log4j. Logback offers a faster implementation, provides more options for configuration, and more flexibility in archiving old log files.

How do I enable logging in Eclipse?

In Eclipse, click on "Window > Preferences" In the "Preferences" window, select "Collaborator" from left pane. From the right panel after selecting "Collaborator", click on the "Capture Debugging Log" button and close the "Preferences" window.


1 Answers

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

like image 196
Olof Åkesson Avatar answered Oct 02 '22 23:10

Olof Åkesson