Search code examples
apache-camellog4j2apache-karaf

How to configure Karaf org.ops4j.pax.logging.cfg to use a sift appender based on the log4j2 logging category


I'm using Karaf and Camel and have been able to configure PAX logging to sift on MDC fields (camel.routeId) and that works just fine.

I'm wondering if I can configure log4j2 to sift on the logging category field (%c or %logger in log4j2 conversion pattern terms) or if anyone can point me in the right direction as to how I could go about configuring it.


Solution

  • Log4j2 (pax-logging-log4j2) is "sifting" on the basis of MDC data. By default logger/category is not part of this context data. You can however put the logger name to MDC yourself.

    In pax-logging-log4j2, org.ops4j.pax.logging.log4j2.internal.PaxLoggerImpl#setDelegateContext() method sets 3 keys:

    • bundle.id
    • bundle.name
    • bundle.version

    Camel sets own keys (like context-id) in org.apache.camel.impl.MDCUnitOfWork constructor.