How to make a Logger for System.out

I am wondering how to get org.slf4j.Logger for System.out. I know this is not good, but I need it for testing purposes.

Thank you so much.

1

4 Answers

It is possible to use slf4j-simple and make it write to the standard output by setting a system property when the program starts:

System.setProperty("org.slf4j.simpleLogger.logFile", "System.out");

More information at

Put simplelogger.properties in your classpath and put this line in it:

org.slf4j.simpleLogger.logFile=System.out

This will cause SLF4J Simple Logger to log to Standard Output instead of Standard Error.

1

SLF4J is a logging facade. You need a logging implementation.

Nowadays, Logback is the recommanded logging framework.

To log to System.out, you have to use the ConsoleAppender in Logback configuration file.

Example :

<appender name="stdout"> <target>System.out</target> <encoder> <pattern>%-40.40c [%5.5thread] %-5p %X - %m%n</pattern> </encoder>
</appender>
1

This might help: sysout-over-slf4j

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like