Hey Juergen,
Glad to see here developers who rely on openHAB. :)

The MDC context is not lost, but as this is a diagnostic context it might be ephemeral. Can you share code piece how you set MDC?
Look at example how to do it with slf4j [1].

Normally all MDC operations are put into closeable context, so diagnostic information is set during operation and cleared once it is done. We obviously have exceptions, cause some diagnostic context can be identified in an permanent way. Construction of pax logging can guarantee that bundle related context is always propagated, cause it can control loggers which are being requested by them. This is likely not a case in situations where you request distinct loggers elsewhere or logger instance is reused across threads. As far I remember MDC scope is usually just a thread.

Best,
Łukasz

[1] https://github.com/apache/plc4x/blob/v0.9.1/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/transaction/RequestTransactionManager.java#L207L211


On 4.01.2022 10:42, Jürgen Weber wrote:
This is about openHAB 3.2 which uses Karaf 4.3.4 and Pax logging.

The idea is to put data into an MDC in a bundle and use it for log4j2 routes.

I tried this in a Java main sample and it works:

MDC.put("ohtopic", "openhab/items/XLevel/state");

<Routes pattern="$${ctx:ohtopic}">
<Route key="openhab/items/XLevel/state" ref="FILE1">
</Route>

But not within openHAB / karaf, there only the bundle id etc. appear
in log4j2 (as shown with %X pattern).

Thanks,
Juergen

Am Di., 4. Jan. 2022 um 09:53 Uhr schrieb Jean-Baptiste Onofré
<j...@nanthrax.net>:

Hi,

Are you using the SIFT appender ?

Which Karaf version are you using ?

Does it mean that you set a MDC property that you don't see later on ?

Are you using something similar to:

https://nanthrax.blogspot.com/2014/08/mdc-logging-with-apache-karaf-and-camel_31.html

aka MDC.put("foo", "bar"); ?

?

Regards
JB

On 03/01/2022 22:32, Jürgen Weber wrote:
Seems if a user code in a bundle sets a logging MDC it gets deleted/is
lost? by Karaf. Is this indeed the case? by design?

%X in the appender pattern shows only

{bundle.id=175, bundle.name=org.openhab.core.io.monitor, bundle.version=3.2.0}

Thanks,
Juergen

Reply via email to