WebSphere-无法加载Logmanager"org.apache.logging.log4j.jul.LogManager"; [英] WebSphere - Could not load Logmanager "org.apache.logging.log4j.jul.LogManager"

查看:504
本文介绍了WebSphere-无法加载Logmanager"org.apache.logging.log4j.jul.LogManager";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行WebApp的WebSphere Application Server.我从Eclipse启动服务器.该应用程序中的主要日志记录框架是log4j2,但是有一些使用java.util.logging的第三方库.我想将这些日志重定向到log4j2,以便它使用我的过滤器,日志格式等.

I have an WebSphere Application Server which runs an WebApp. I start the Server from Eclipse. The main logging framework in that application is log4j2, but there are some third party libraries which use java.util.logging. I want to redirect those logs to log4j2 so it uses my filters, log format etc.

因此,我尝试添加 Log4j JDK日志记录适配器.我在构建路径和部署程序集中添加了必要的JAR(仅缺少log4j-jul,因为我已经有其他的log4j-jars用于其他用途),并在我的jvm.options中添加了行-Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager.

Therefore I tried to add the Log4j JDK Logging Adapter. I added the necessary JAR (I lacked only log4j-jul as I already had the other log4j-jars for other purposes) to the Build Path and to the Deployment Assembly and added the line -Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager to my jvm.options.

启动后,立即出现以下异常:

Immediatly after startup I get the following exception:

Could not load Logmanager "org.apache.logging.log4j.jul.LogManager"
java.lang.ClassNotFoundException: org.apache.logging.log4j.jul.LogManager
    at java.net.URLClassLoader.findClass(URLClassLoader.java:609)
    at java.lang.ClassLoader.loadClassHelper(ClassLoader.java:850)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:829)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:329)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:809)
    at java.util.logging.LogManager$1.run(LogManager.java:206)
    at java.util.logging.LogManager$1.run(LogManager.java:192)
    at java.security.AccessController.doPrivileged(AccessController.java:594)
    at java.util.logging.LogManager.<clinit>(LogManager.java:192)
    at java.util.logging.Logger.demandLogger(Logger.java:459)
    at java.util.logging.Logger.getLogger(Logger.java:513)
    at com.sun.jmx.remote.util.ClassLogger.<init>(ClassLogger.java:67)
    at javax.management.NotificationBroadcasterSupport.<clinit>(NotificationBroadcasterSupport.java:376)
    at com.ibm.lang.management.OperatingSystemMXBeanImpl.<init>(OperatingSystemMXBeanImpl.java:38)
    at com.ibm.lang.management.ExtendedOperatingSystem.<clinit>(ExtendedOperatingSystem.java:23)
    at com.ibm.lang.management.RuntimeMXBeanImpl.<clinit>(RuntimeMXBeanImpl.java:29)
    at com.ibm.lang.management.ManagementUtils.getRuntimeBean(ManagementUtils.java:402)
    at java.lang.management.ManagementFactory.getRuntimeMXBean(ManagementFactory.java:393)
    at com.ibm.ws.logging.internal.impl.LogProviderConfigImpl.getLogHeader(LogProviderConfigImpl.java:259)
    at com.ibm.ws.logging.internal.impl.LogProviderConfigImpl.<init>(LogProviderConfigImpl.java:177)
    at com.ibm.ws.logging.internal.impl.LogProviderImpl.configure(LogProviderImpl.java:31)
    at com.ibm.ws.kernel.launch.internal.LauncherDelegateImpl.getLogProviderImpl(LauncherDelegateImpl.java:185)
    at com.ibm.ws.kernel.launch.internal.LauncherDelegateImpl.launchFramework(LauncherDelegateImpl.java:91)
    at com.ibm.ws.kernel.boot.internal.KernelBootstrap.go(KernelBootstrap.java:212)
    at com.ibm.ws.kernel.boot.Launcher.handleActions(Launcher.java:246)
    at com.ibm.ws.kernel.boot.Launcher.createPlatform(Launcher.java:121)
    at com.ibm.ws.kernel.boot.cmdline.EnvCheck.main(EnvCheck.java:59)
    at com.ibm.ws.kernel.boot.cmdline.EnvCheck.main(EnvCheck.java:35)

我不知道此堆栈跟踪中的大多数类,但对我来说,似乎异常抛出得很早,也许是在设置JVM时抛出的,而且尚不知道打包在我的.war文件中的jars .

I don't know most of the classes in this stack trace but to me it looks like the exception is thrown very early, maybe while setting up the JVM, and that the jars packed in my .war file are not yet known.

问题是,根据上面链接的log4j文档,我需要在LogManager的第一次调用之前为LogManager设置系统属性,这实际上似乎是在堆栈中的NotificationBroadcasterSupport中发生的痕迹.

The problem is that according to the log4j documentation linked above, I need to set the System Property for the LogManager before the first call of the LogManager, which indeed seems to happen in the NotificationBroadcasterSupport from the stack trace.

在启动的这一阶段是否有办法让罐子知道?

Is there a way to make the jar known at this stage of startup?

编辑,我问了一个后续问题

Edit I asked a follow up question here and followed the suggestion there to use the Log4jBridgeHandler instead of swapping out the LogManager.

推荐答案

这里的问题是使用java.util.logging(JUL)的不仅是您的应用-服务器的核心也是如此,并且通过尝试将JUL重定向到Log4J并使用系统属性(适用于整个JVM)对其进行强制,您实际上是在尝试通过Log4J设置来重定向服务器中的所有日志记录.服务器的messages.log中包含的所有内容都将显示在您的日志记录中.

The problem here is that it's not just your app that uses java.util.logging (JUL) - so does the core of the server, and by attempting to redirect JUL to Log4J and enforcing it with a system property (which applies to the entire JVM), you're essentially attempting to redirect all logging in the server through your Log4J setup. Anything that would be in the server's messages.log is going to show up in your logging instead.

如果您仍然真的想要这样做,最简单的解决方案可能是将log4j-jul jar放入JVM启动类路径,因此对于Java系统加载器来说是可见的(您可能必须对任何依赖项执行相同的操作和配置文件).同样,您将覆盖所有服务器级别的日志记录,因此我不希望这是受支持的配置(如果打开支持案例,他们将不想查看您的自定义Log4J格式的日志以获取服务器详细信息),但从理论上讲应该可以正常工作.

If you still REALLY want to do this, the simplest solution is probably to put the log4j-jul jar into the JVM launch class path, so it's visible to the Java system loader (you may have to do the same with any dependencies and configuration files). Again, you're overriding all of the server-level logging, so I wouldn't expect that this would be a supported configuration (if you open a support case, they're not gonna want to review your custom Log4J-formatted logs for server details), but it should theoretically be functional.

这篇关于WebSphere-无法加载Logmanager"org.apache.logging.log4j.jul.LogManager";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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