Expecting Log4j LoggerContext in plugin library

Having trouble installing Oxygen? Got a bug to report? Post it all here.
changke
Posts: 17
Joined: Tue Aug 15, 2023 10:58 pm

Expecting Log4j LoggerContext in plugin library

Post by changke »

Hi,
I am working on a workbench plugin for Oxygen XML Editor 25. Our plugin uses APIs from one of our library to connect to another application from Oxygen. The library uses log4j. But we run oxygen editor from eclipse. we got following

Caused by: java.lang.ClassCastException: class org.apache.logging.slf4j.SLF4JLoggerContext cannot be cast to class org.apache.logging.log4j.core.LoggerContext (org.apache.logging.slf4j.SLF4JLoggerContext and org.apache.logging.log4j.core.LoggerContext are in unnamed module of loader 'app')
SLF4JLoggerContext
the reason is that LogManager.getContext(false) returns SLF4JLoggerContext, but the code in the library try to cast to org.apache.logging.log4j.core.LoggerContext.

Is there a way to return org.apache.logging.log4j.core.LoggerContext while LogManager.getContext(false) is called in plugin libraries?
In Oxygen XML Editor 25 there are slf4j jars.in lib. Should we remove slf4j jars from lib? is there another way to avoid the logger context issue

Thanks,

Kehua
Radu
Posts: 9205
Joined: Fri Jul 09, 2004 5:18 pm

Re: Expecting Log4j LoggerContext in plugin library

Post by Radu »

Hi Kehua,
Oxygen uses the SLF4j Logger for logging. It also comes with a JAR library which is a bridge between SLF4j and Log4j.
So:
Is there a way to return org.apache.logging.log4j.core.LoggerContext while LogManager.getContext(false) is called in plugin libraries?
No. Maybe you can try to refer to bundle and refer to the Log4j libraries in your own Eclipse plugin. Or use SLF4j for logging in your plugin.
In Oxygen XML Editor 25 there are slf4j jars.in lib. Should we remove slf4j jars from lib? is there another way to avoid the logger context issue
In general you must not make changes inside the Oxygen plugin folder, if you were to do what you suggested for example the Oxygen plugin would break completely because it uses SLF4j extensively.
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply