Hi!

My use case: I want name log files based on XML file names that I'm
processing. E.g. if the file name is "sample.xml" log output would go
to "incoming.xml.log".

I have read about MDC support in Camel and Karaf, and based on that
I've come up with a working solution: I put the XML file name into MDC
in the beginning of the processing like so:

public class PutIncomingFileNameToMDC {
    private static final String MDC_KEY_FILE_NAME = "fileName";

    public void putIncomingFileNameToMDC(
            @Header(Exchange.FILE_NAME_ONLY) String fileName) {
        MDC.put(MDC_KEY_FILE_NAME, fileName);
    }
}

Then I specify MDCSiftingAppender in Karaf's configuration. This
solution works OK until I use a splitter with
parallelProcessing="true" on one of my routes. I did some digging and
found class MDCUnitOfWork which seems to fix this for Camel's
predefined MDC values (exchangeId etc) when useMDCLogging is set to
"true" in Came context.

Any suggestions how should I apply the fix to my own custom MDC value
("fileName")? Would it be possible to get built-in support for this in
Camel somehow?

Camel version: 2.12.4
Karaf version: 2.3.5
Java version: 1.7.0_51
Platform: Windows

BR,
Joni Nousiainen

Reply via email to