记录器对整个输出使用相同的颜色



我正在尝试设置slf4j
当我简单地打印一个信息和一个错误时,我会得到以下输出:

FATAL:   [http-thread-pool::http-listener-1(5)] INFO com.company.myclass - this is an information  
FATAL:   [http-thread-pool::http-listener-1(5)] ERROR com.company.myclass - this is an error

除了INFOERROR这两个词外,还有相似的,它们甚至有相同的颜色——红色

这真的是想要的输出吗
难道INFO不应该换一种颜色,这样就可以把它们分开吗?

这是我的代码:

Logger log = LoggerFactory.getLogger(this.getClass());
log.info("this is an information");
log.error("this is an error");

我添加了这个Maven依赖项:SLF4J Simple Binding»1.7.25。

您得到的消息是红色的,因为当未定义logFileprivate static String LOG_FILE_DEFAULT = "System.err";时,slf4j simple默认使用System.err作为默认输出。您可以在源代码中检查它。

如果您希望消息以白色打印,您可以使用以下参数-Dorg.slf4j.simpleLogger.logFile=System.out指定输出,在这种情况下,System.err将被System.out取代。

如果您选择其他日志库(如Log4j)并提供配置文件,您会注意到日志也将显示为白色。

最新更新