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?
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.
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.
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.
The configuration file needs to be on the classpath. My guess is that it isn't. Check the build path for the project.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With