Page 1 of 1

Expecting Log4j LoggerContext in plugin library

Posted: Fri Sep 29, 2023 8:57 am
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

Re: Expecting Log4j LoggerContext in plugin library

Posted: Fri Sep 29, 2023 10:40 am
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