自定义 Log4j 来过滤 PatternLayout

发布于 2024-08-23 21:06:56 字数 365 浏览 3 评论 0原文

我刚刚开始迁移到 WLS 10.x,并注意到 WL 的线程名称 [%t] 非常冗长,并且比我的部署需求所需的信息更多。

最终,我只关心线程 ID,但 WL 给了我这个:<

[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)'
~

有谁知道 log4j 中是否有一种方法可以编写一个自定义过滤器,该过滤器允许我覆盖 PatternLayout 这样我就可以解析 WLS 线程名称以仅输出线程 ID,在上面的情况下为 0 ?我宁愿扩展然后自定义,因为它使升级库变得更加容易。

I have just starting migrating to WLS 10.x and have noticed that the thread name [%t] for WL is quite verbose and more informative than I need for my deployment needs.

Ultimately, I only care about the thread ID but WL gives me this:<

[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)'
~

Does anybody know if there is a way in log4j to write a custom filter that will allow me to override PatternLayout so I can parse the WLS Thread Name to just output the thread ID which in this case above is 0 ? I'd rather extend then customize as it makes upgrading libraries so much easier.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

阳光下慵懒的猫 2024-08-30 21:06:56

您想编写自己的转换词。在 logback 中,您可以在几分钟内完成此操作。请参阅自定义转换说明符部分。

如果您真的很懒并且懒得编写自定义转换字,只需告诉现有的 throwable 将线程名称修剪为 26 个字符即可。该模式将是“%.-26thread”。我选择 26,因为这是“[ACTIVE] ExecuteThread: '0'”的长度。

You want to write your own conversion word. In logback you can do so within minutes. See the section on custom conversion specifiers.

If you are really lazy and could not be bothered with writing a custom conversion word, just tell the the existing throwable to trim the thread name to 26 characters. The pattern would be "%.-26thread". I chose 26 because that is the length of "[ACTIVE] ExecuteThread: '0'".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文