Hi Jochen,

If you want to be "low level", you have to create a fragment on
pax-logging-log4j2 to add your appender.
It's similar to what I explain in this blog:
http://blog.nanthrax.net/?p=333 (just use pax-logging-log4j2 as host). I
just did this in my company yesterday (for a layout pattern and an
appender).

You have another possible approach is to create a Pax Logging
PaxAppender. Then you don't need a fragment, just registering a
PaxAppender service.
It's what we are using in Decanter for the log collector:

https://github.com/apache/karaf-decanter/blob/master/collector/log/src/main/java/org/apache/karaf/decanter/collector/log/LogAppender.java

You should not use the ConfigurationBuilder directly anyway, better to
create your own appender and delegate the configuration to pax-logging.

Regards
JB

On 07/06/2019 09:10, jochenw wrote:
> Hi,
> 
> in my application, I want to programmatically add a log appender. The
> org.ops4j.pax.logging.cfg file should be left untouched (meaning that I
> don't want to use ConfigAdmin to change the configuration).
> 
> When trying with the log4j ConfigurationBuilder to configure the appender
> and the logger, and then the Configurator to activate it, following error
> appears:
> 
> /LogManager returned an instance of
> org.ops4j.pax.logging.log4jv2.Log4jv2LoggerContextFactory which does not
> implement org.apache.logging.log4j.core.impl.Log4jContextFactory. Unable to
> initialize Log4j/.
> 
> My pom contains the pax-logging-api and pax-logging-log4j2 bundles as
> dependencyies, both with version 1.10.1.
> 
> Is there a way to get this right, or another way to create a log appender
> via code? Please note that I don't want to create a custom appender, just
> configure a rolling file appender, but from code instead of from config
> file.
> 
> Best Regards
> 
> Jochen
> 
> 
> 
> --
> Sent from: http://karaf.922171.n3.nabble.com/Karaf-User-f930749.html
> 

-- 
Jean-Baptiste Onofré
[email protected]
http://blog.nanthrax.net
Talend - http://www.talend.com

Reply via email to