You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Mark <el...@gmail.com> on 2017/10/04 18:03:57 UTC

log exception message, not stack trace

I've been looking through the source code and documentation for this.  I'd
like to log the exception message to our log file and not the entire stack
trace.  Is this something that can be done with the current baseline or do
I need to write a custom ErrorHandler?

Re: log exception message, not stack trace

Posted by Mark <el...@gmail.com>.
Thanks Claus, that helps.  I'm still seeing stack traces in my route.  I
receive JSON data from an external source, and I'm trying to unmarshal the
JSON to an Java object that I've written.  If the JSON is bad/poorly
formed, I still see a JsonMappingException getting thrown in the log.  I
have the following route defined:

return new RouteBuilder() {
    public void configure() {
        deadLetterChannel("direct:errors");
        boolean handled = true;

onException(JsonMappingException.class).handled(handled).to("direct:errors").end();

        from("direct:start")
            .unmarshal(df)
            .to("mock:end");

        from("direct:errors")
            .transform(simple("Message parsing error --
${exception.message}"))
            .to("log:parse-error?level=ERROR");
    }
};

And I see the following stack trace in my log:

com.fasterxml.jackson.databind.JsonMappingException: Missing creator
property 'name' (index 0);
DeserializationFeature.FAIL_ON_MISSING_CREATOR_PROPERTIES enabled
 at [Source: java.io.ByteArrayInputStream@1d8bd0de; line: 1, column: 81]
at
com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:148)
at
com.fasterxml.jackson.databind.DeserializationContext.mappingException(DeserializationContext.java:878)
<more of the stack trace>


On Wed, Oct 4, 2017 at 2:55 PM, Claus Ibsen <cl...@gmail.com> wrote:
>
> On Wed, Oct 4, 2017 at 8:49 PM, Mark <el...@gmail.com> wrote:
> > Sorry for the confusion.  Its the log file that is used by log4j.
> >
>
> Okay so you need to transform the error message you want to write to
> that log, you can do this by setting a dead letter channel error
> handler, and then route to a direct endpoint where you can then do a
> message transformation where you can build the error message, and then
> route it to the log endpoint
>
> dead letter channel (direct:myerror)
>
> from direct:myerror
>    transform simple("Darn something went wrong because
${exception.message}")
>    to log:myerror?level=ERROR
>
>
>
>
>
> >
> > On Wed, Oct 4, 2017 at 2:44 PM, Claus Ibsen <cl...@gmail.com>
wrote:
> >
> >> It depends a bit what you mean by our log file? Is it the log file you
> >> may use with log4j or logback. Or do you want Camel to write to a
> >> special log file via its file component.
> >>
> >>
> >> On Wed, Oct 4, 2017 at 8:23 PM, Mark <el...@gmail.com> wrote:
> >> > Do you know what this option is and will all logging be turned off or
> >> just
> >> > the stack trace ?
> >> >
> >> >
> >> > On Wed, Oct 4, 2017 at 2:09 PM, Claus Ibsen <cl...@gmail.com>
> >> wrote:
> >> >
> >> >> There is an option to turn off logging the stacktrace on the error
> >> >> handler / onException etc
> >> >>
> >> >> On Wed, Oct 4, 2017 at 8:03 PM, Mark <el...@gmail.com> wrote:
> >> >> > I've been looking through the source code and documentation for
this.
> >> >> I'd
> >> >> > like to log the exception message to our log file and not the
entire
> >> >> stack
> >> >> > trace.  Is this something that can be done with the current
baseline
> >> or
> >> >> do
> >> >> > I need to write a custom ErrorHandler?
> >> >>
> >> >>
> >> >>
> >> >> --
> >> >> Claus Ibsen
> >> >> -----------------
> >> >> http://davsclaus.com @davsclaus
> >> >> Camel in Action 2: https://www.manning.com/ibsen2
> >> >>
> >>
> >>
> >>
> >> --
> >> Claus Ibsen
> >> -----------------
> >> http://davsclaus.com @davsclaus
> >> Camel in Action 2: https://www.manning.com/ibsen2
> >>
>
>
>
> --
> Claus Ibsen
> -----------------
> http://davsclaus.com @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2

Re: log exception message, not stack trace

Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, Oct 4, 2017 at 8:49 PM, Mark <el...@gmail.com> wrote:
> Sorry for the confusion.  Its the log file that is used by log4j.
>

Okay so you need to transform the error message you want to write to
that log, you can do this by setting a dead letter channel error
handler, and then route to a direct endpoint where you can then do a
message transformation where you can build the error message, and then
route it to the log endpoint

dead letter channel (direct:myerror)

from direct:myerror
   transform simple("Darn something went wrong because ${exception.message}")
   to log:myerror?level=ERROR





>
> On Wed, Oct 4, 2017 at 2:44 PM, Claus Ibsen <cl...@gmail.com> wrote:
>
>> It depends a bit what you mean by our log file? Is it the log file you
>> may use with log4j or logback. Or do you want Camel to write to a
>> special log file via its file component.
>>
>>
>> On Wed, Oct 4, 2017 at 8:23 PM, Mark <el...@gmail.com> wrote:
>> > Do you know what this option is and will all logging be turned off or
>> just
>> > the stack trace ?
>> >
>> >
>> > On Wed, Oct 4, 2017 at 2:09 PM, Claus Ibsen <cl...@gmail.com>
>> wrote:
>> >
>> >> There is an option to turn off logging the stacktrace on the error
>> >> handler / onException etc
>> >>
>> >> On Wed, Oct 4, 2017 at 8:03 PM, Mark <el...@gmail.com> wrote:
>> >> > I've been looking through the source code and documentation for this.
>> >> I'd
>> >> > like to log the exception message to our log file and not the entire
>> >> stack
>> >> > trace.  Is this something that can be done with the current baseline
>> or
>> >> do
>> >> > I need to write a custom ErrorHandler?
>> >>
>> >>
>> >>
>> >> --
>> >> Claus Ibsen
>> >> -----------------
>> >> http://davsclaus.com @davsclaus
>> >> Camel in Action 2: https://www.manning.com/ibsen2
>> >>
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> http://davsclaus.com @davsclaus
>> Camel in Action 2: https://www.manning.com/ibsen2
>>



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Re: log exception message, not stack trace

Posted by Mark <el...@gmail.com>.
Sorry for the confusion.  Its the log file that is used by log4j.


On Wed, Oct 4, 2017 at 2:44 PM, Claus Ibsen <cl...@gmail.com> wrote:

> It depends a bit what you mean by our log file? Is it the log file you
> may use with log4j or logback. Or do you want Camel to write to a
> special log file via its file component.
>
>
> On Wed, Oct 4, 2017 at 8:23 PM, Mark <el...@gmail.com> wrote:
> > Do you know what this option is and will all logging be turned off or
> just
> > the stack trace ?
> >
> >
> > On Wed, Oct 4, 2017 at 2:09 PM, Claus Ibsen <cl...@gmail.com>
> wrote:
> >
> >> There is an option to turn off logging the stacktrace on the error
> >> handler / onException etc
> >>
> >> On Wed, Oct 4, 2017 at 8:03 PM, Mark <el...@gmail.com> wrote:
> >> > I've been looking through the source code and documentation for this.
> >> I'd
> >> > like to log the exception message to our log file and not the entire
> >> stack
> >> > trace.  Is this something that can be done with the current baseline
> or
> >> do
> >> > I need to write a custom ErrorHandler?
> >>
> >>
> >>
> >> --
> >> Claus Ibsen
> >> -----------------
> >> http://davsclaus.com @davsclaus
> >> Camel in Action 2: https://www.manning.com/ibsen2
> >>
>
>
>
> --
> Claus Ibsen
> -----------------
> http://davsclaus.com @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2
>

Re: log exception message, not stack trace

Posted by Claus Ibsen <cl...@gmail.com>.
It depends a bit what you mean by our log file? Is it the log file you
may use with log4j or logback. Or do you want Camel to write to a
special log file via its file component.


On Wed, Oct 4, 2017 at 8:23 PM, Mark <el...@gmail.com> wrote:
> Do you know what this option is and will all logging be turned off or just
> the stack trace ?
>
>
> On Wed, Oct 4, 2017 at 2:09 PM, Claus Ibsen <cl...@gmail.com> wrote:
>
>> There is an option to turn off logging the stacktrace on the error
>> handler / onException etc
>>
>> On Wed, Oct 4, 2017 at 8:03 PM, Mark <el...@gmail.com> wrote:
>> > I've been looking through the source code and documentation for this.
>> I'd
>> > like to log the exception message to our log file and not the entire
>> stack
>> > trace.  Is this something that can be done with the current baseline or
>> do
>> > I need to write a custom ErrorHandler?
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> http://davsclaus.com @davsclaus
>> Camel in Action 2: https://www.manning.com/ibsen2
>>



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Re: log exception message, not stack trace

Posted by Mark <el...@gmail.com>.
Do you know what this option is and will all logging be turned off or just
the stack trace ?


On Wed, Oct 4, 2017 at 2:09 PM, Claus Ibsen <cl...@gmail.com> wrote:

> There is an option to turn off logging the stacktrace on the error
> handler / onException etc
>
> On Wed, Oct 4, 2017 at 8:03 PM, Mark <el...@gmail.com> wrote:
> > I've been looking through the source code and documentation for this.
> I'd
> > like to log the exception message to our log file and not the entire
> stack
> > trace.  Is this something that can be done with the current baseline or
> do
> > I need to write a custom ErrorHandler?
>
>
>
> --
> Claus Ibsen
> -----------------
> http://davsclaus.com @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2
>

Re: log exception message, not stack trace

Posted by Claus Ibsen <cl...@gmail.com>.
There is an option to turn off logging the stacktrace on the error
handler / onException etc

On Wed, Oct 4, 2017 at 8:03 PM, Mark <el...@gmail.com> wrote:
> I've been looking through the source code and documentation for this.  I'd
> like to log the exception message to our log file and not the entire stack
> trace.  Is this something that can be done with the current baseline or do
> I need to write a custom ErrorHandler?



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2