1
votes

I'm decided to use slf4j instead of Java's very own logging. I've successfully logging to console using slf4j. But I don't know how to write it into a log file. Log file will help us to collect possible errors along the runtime.

I'm implementing slf4j by doing this,

private static final org.slf4j.Logger LOGGER = org.slf4j.LoggerFactory.getLogger(Class1.class);

Then i'm initializing the log4j properties,

PropertyConfigurator.configure(new FileInputStream("log4j.properties"));

Thanks!

1

1 Answers

2
votes

slf4j is only an API, you need to add a loggers engine (and it is easy to switch between them). You have to choose one (logback for exmaple) and add a configuration file to configure it to write it to files.

As mentioned at the slf4j site:

The Simple Logging Facade for Java (SLF4J) serves as a simple facade or abstraction for various logging frameworks (e.g. java.util.logging, logback, log4j) allowing the end user to plug in the desired logging framework at deployment time.