我想知道如何为 System.out 获取 org.slf4j.Logger。我知道这不好,但我需要它来进行测试。
太感谢了。
可以使用 slf4j-simple 并通过在程序启动时设置系统属性将其写入标准输出:
System.setProperty("org.slf4j.simpleLogger.logFile", "System.out");
更多信息请访问http://www.slf4j.org/api/org/slf4j/impl/SimpleLogger.html
将 simplelogger.properties 放入您的类路径中,并将这一行放入其中:
org.slf4j.simpleLogger.logFile=System.out
这将导致 SLF4J 简单记录器记录到标准输出而不是标准错误。
SLF4J 是一个日志外观。您需要一个日志记录实现。
如今,Logback 是推荐的日志框架。
要登录到 System.out,您必须使用 Logback 配置文件中的 ConsoleAppender。
例子 :
<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
<target>System.out</target>
<encoder>
<pattern>%-40.40c [%5.5thread] %-5p %X - %m%n</pattern>
</encoder>
</appender>
这可能会有所帮助:sysout-over-slf4j