简体   繁体   English

在 slf4j/logback 中监听日志消息

[英]Listening for Log Messages in slf4j/logback

I have a Swing-based application without a console that logs all messages to text files through slf4j with logback underneath.我有一个基于 Swing 的应用程序,没有控制台,它通过 slf4j 将所有消息记录到文本文件中,下面有 logback。

Whenever a message is logged, I'd also like to add it to a JTextArea for the end user to see on the screen.每当记录一条消息时,我还想将其添加到JTextArea以供最终用户在屏幕上查看。

These messages should be formatted the sameway as the log files for consistency.为了保持一致性,这些消息的格式应与日志文件的格式相同。

Does slf4j/logback have API that lets you add a listener for log messages so that I can copy them to JTextArea ? slf4j/logback 是否具有允许您为日志消息添加侦听器以便我可以将它们复制到JTextArea API?

Logback Appenders are listeners for log messages. Logback Appenders是日志消息的监听器。 Just implement a custom appender that will log in a JTextArea .只需实现一个将登录JTextArea的自定义 appender。

You can then create, configure and add appenders to loggers programmatically, or using an external config file ( logback.xml )然后,您可以以编程方式或使用外部配置文件 ( logback.xml ) 创建、配置和添加 appender 到记录器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM