Configure Logs in Eclipse

Right now I am moving from Log4j to Logback, but I have no success in making Logback work not done yet. I placed logback.xml in the root directory of my Java Eclipse project, and below its contents:

 <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 work because a file named myApp.log is not created in the Java Eclipse root application. Any idea what I'm doing wrong?

+8
java logging slf4j logback
source share
1 answer

The configuration file must be in the class path. I guess that is not the case. Check the build path for the project.

+8
source share

All Articles