Reputation: 2897
I'm using the SimpleLogger binding for SLF4J 1.7.5. As per the docs I can use the org.slf4j.simpleLogger.logFile property in my simplelogger.properties file to specify a log file OR System.out OR System.err.
However I want to send log messages to BOTH System.out AND a log file. Does anyone know how to achieve this using SimpleLogger please? (I'm using Windows so cannot use tail -f simply to follow the log file in a console window; nor do I want to get a third party utility which emulates 'tail -f' in Windows.)
Upvotes: 7
Views: 8339
Reputation: 38300
Instead of using slf4j-simple-1.x.x.jar get logback (logback-classic.jar and logback-core.jar). With logback you can define two appenders; one for the file output and one for console (also-known-as System.out) output.
Instead of using slf4j-simple.1.x.x.jar get xxx (substitute any logging system supported by slf4j) and blah blah blah (do the same as in 1 obove).
SLF4j is open source; derive your own logger (lets call it TeeLogger) that logs to System.out and a file.
Create a logging class that that sits in front of SLF4j (in your application). Have it take a Logger and a messasge then have it write the message to System.out and the Logger.
Something that I have not though about.
Here is a (super simplistic) example of #4 above:
import org.slf4j.Logger;
public class LoggyLoo
{
public static void logZoreInfo(
final Logger logger,
final String message)
{
System.out.println(message);
logger.info(message);
}
}
Upvotes: 11