1 Reply Latest reply on May 11, 2011 7:39 AM by davsclaus

    Logging an error with exception and message

    grahamp

      If this is in the FAQ, please tell me where the FAQ is!

       

      I can't seem to get both the message body and the exception text value into the logs.  The route is really simple - just puts a message through an XSD validation:

       

           from("file:/home/validationIn")

                .to("validator:schema/forecast-volume.xsd")

                .to("file:/home/validationOut");

       

      And I want to trap failed validation and dump info to log. 

       

      DeadLetterApproach

       

           errorHandler(

                     deadLetterChannel("log:MyLog")

                          .maximumRedeliveries(0)

                          .logStackTrace(true)

           );

       

      but that only logs the message body.  The logStackTrace(true) has no effect, I guess  because the dead letter handler has "handled" the exception and discarded the trace.  If I set handled(false) then the message is logged to MyLog and the stack trace is logged to DeadLetterChannel and GenericFileOnCompletion, but the route retries indefinitely.

       

      Exception Handler Approach

       

                onException(SchemaValidationException.class)

                     .handled(true)

                     .to("log:MyLog")

                     .transform(exceptionMessage())

                     .to("log:MyLog");

       

      This is the only way I've managed to get both the original data and the exception message into the logs.  But they appear as two separate entries - which could be hard to correlate in a heavily loaded production environment.

       

      Does anyone know if there is a simple way to create a log entry containing the original message and the exception message?  Or do I just have to forward it to a custom Process and do my own logging?

       

       

       

      P.S. my code indentation above has disappeared .. is there a markup like html

      or snipsnap  to keep literal text?