Search code examples
apache-camel

Problem with registering Camel LogListener in version 3.x


I have been using camel LogListener to intercept all log messages from log EIP and massage those with some custom headers and exchange properties. All seemed to be working fine until we migrated from v2.23.x to v3.19.0. Ever since we upgraded, the LogListener has stopped working.

Before migration, we only did this:

            log.info("Registering log listener");
            getContext().addLogListener(new CustomLogListener());

And then our CustomLogListener looked like:

public class CustomLogListener implements LogListener {

    @Override
    public String onLog(final Exchange exchange, final CamelLogger camelLogger, final String message) {
        return String.format("traceId=%s TXN=%s TENANT=%s %s",exchange.getProperty(TOP_TRACEID, String.class),exchange.getProperty(TRANSACTION_ID, String.class), exchange.getProperty(TOPUP_ENV_HEADER, String.class), message);
    }
}

After migration, we no longer can do context.addLogListener(...)

We tried the following:

TopLogListener logListener = new TopLogListener(); getContext().getRegistry().bind("logListener", logListener);

but it didn't help. Any leads would be much appreciated.

P.S: Our application uses Jakarta JEE and is packaged as a war file and deployed in wildfly. It doesn't use spring boot.


Solution

  • In Camel 3.19.x you can register the LogListener like:

    MyCustomLogListener logListener = new MyCustomLogListener();
    getCamelContext().adapt(ExtendedCamelContext.class).addLogListener(logListener)
    

    There's some more background info in the Camel 2.x - 3.x migration guide about APIs that got moved from CamelContext to ExtendedCamelContext:

    https://camel.apache.org/manual/camel-3-migration-guide.html#_extended_camelcontext