log4j2:为异步日志记录设置Log4jContextSelector系统属性的位置 [英] log4j2: Location for setting Log4jContextSelector system property for asynchronous logging

查看:449
本文介绍了log4j2:为异步日志记录设置Log4jContextSelector系统属性的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在当前在自由配置文件服务器中运行的REST Web方法中设置异步日志记录(出于性能原因)。

I am attempting to set up asynchronous logging (for performance reasons) within REST web methods that currently run in a liberty profile server.

为此,我已经设置了以下属性:

In order to do this, I have set up the following property:

System.setProperty("Log4jContextSelector", "org.apache.logging.log4j.core.async.AsyncLoggerContextSelector");

我的问题是无论我在哪里这样做,有时它都有效,而且记录非常快,有时它没有。

My problem is that no matter where I do this, sometimes it works and logging is very fast, and sometimes it doesn't.

我在包含所有REST Web方法的类的构造函数中尝试过(a)
(b)在过滤器doFilter中在REST方法之前调用的方法
(c)在过滤器初始化方法中
(d)在REST方法本身中

I have tried (a) in the constructor for the class containing all the REST web methods (b) in the filter doFilter method that gets called prior to the REST method (c) in the filter init method (d) in the REST method itself

没有这些位置一致地工作。

None of these locations work consistently.

任何人都可以提供此行为的解释,如果可能的话,建议解决问题的方法。

Can anyone offer an explanation for this behaviour, and if possible a suggested way of fixing the problem.

编辑:似乎在调用setProperty之前初始化了log4j。所以我需要做的是通过自由配置文件设置属性。

It appears that log4j is being initialised prior to calling setProperty. So what I need to do is set up the property via liberty profile instead.

推荐答案

所以显然我需要添加一行到jvm.options文件

So apparently I needed to add a line to the jvm.options file

-DLog4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector

jvm.options文件位于:

The jvm.options file is located here:

${server.config.dir}/jvm.options

可以使用以下链接找到目录:

And that directory can be found by using the link:

http://www-01.ibm.com /support/knowledgecenter/SSEQTP_8.5.5/com.ibm.websphere.wlp.doc/ae/rwlp_dirs.html?cp=SSEQTP_8.5.5%2F1-3-11-0-2-0

在我的情况下,它位于:C:\ eclipse \runtime\usr \servers \ serverName

In my case it is at: C:\eclipse\runtime\usr\servers\serverName

这篇关于log4j2:为异步日志记录设置Log4jContextSelector系统属性的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆