You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Nuno Santos <nf...@gmail.com> on 2013/07/03 15:51:58 UTC

Custom logging of exceptions by file component

Hello everyone,

I'm using the Camel File component to monitor a directory for any file
written there and upload them to a server. Once a file is uploaded, it is
moved to a different directory. If the upload attempt fails, the file is
left in place and another attempt is made to upload it in the next poll
cycle of the File component. The code looks like this:

fromF("file://%s", directory)
  .process(new Processor() {
    @Override
    public void process(Exchange exchange) throws Exception {
      // try to upload to a web server. Throw exception if failed
    });

This is working fine except that whenever an upload fails, camel logs a
message with a large stack trace. This means that every second or so the log
files grow by a couple of hundreds of lines, which is not ideal. I want to
do custom logging of this message, eg., print a single line with a short
message for each attempt. But so far, I haven't found a way of doing this.

If I add a custom error handler to the route above and mark the exception as
handled, the file component thinks that everything succeeded and deletes the
file. If I don't mark it as handled, the exception will still be logged by
the file component after it rollsback. Is it possible to change the way that
the File component logs these exceptions?

Thank you advance



--
View this message in context: http://camel.465427.n5.nabble.com/Custom-logging-of-exceptions-by-file-component-tp5735152.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Custom logging of exceptions by file component

Posted by Christian Müller <ch...@gmail.com>.
Check out the following links:

http://camel.apache.org/exception-clause.html
http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/processor/RedeliveryPolicy.html


Best,
Christian
-----------------

Software Integration Specialist

Apache Camel committer: https://camel.apache.org/team
V.P. Apache Camel: https://www.apache.org/foundation/
Apache Member: https://www.apache.org/foundation/members.html

https://www.linkedin.com/pub/christian-mueller/11/551/642


On Wed, Jul 3, 2013 at 3:51 PM, Nuno Santos <nf...@gmail.com> wrote:

> Hello everyone,
>
> I'm using the Camel File component to monitor a directory for any file
> written there and upload them to a server. Once a file is uploaded, it is
> moved to a different directory. If the upload attempt fails, the file is
> left in place and another attempt is made to upload it in the next poll
> cycle of the File component. The code looks like this:
>
> fromF("file://%s", directory)
>   .process(new Processor() {
>     @Override
>     public void process(Exchange exchange) throws Exception {
>       // try to upload to a web server. Throw exception if failed
>     });
>
> This is working fine except that whenever an upload fails, camel logs a
> message with a large stack trace. This means that every second or so the
> log
> files grow by a couple of hundreds of lines, which is not ideal. I want to
> do custom logging of this message, eg., print a single line with a short
> message for each attempt. But so far, I haven't found a way of doing this.
>
> If I add a custom error handler to the route above and mark the exception
> as
> handled, the file component thinks that everything succeeded and deletes
> the
> file. If I don't mark it as handled, the exception will still be logged by
> the file component after it rollsback. Is it possible to change the way
> that
> the File component logs these exceptions?
>
> Thank you advance
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Custom-logging-of-exceptions-by-file-component-tp5735152.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: Custom logging of exceptions by file component

Posted by ltsallas <le...@yahoo.com>.
Take a look at 


http://camel.apache.org/eventnotifier-to-log-details-about-all-sent-exchanges.html 

I think you can implement a custom event notifier and log everything you
like when  ExchangeFailedEvent occurs



--
View this message in context: http://camel.465427.n5.nabble.com/Custom-logging-of-exceptions-by-file-component-tp5735152p5735154.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Custom logging of exceptions by file component

Posted by Nuno Santos <nf...@gmail.com>.
Problem solved, I found out that we can use allowRedeliveryWhileStopping() on
the error handler to force shutdown of a route even with pending exchanges.
So now it works nicely.

Nuno



--
View this message in context: http://camel.465427.n5.nabble.com/Custom-logging-of-exceptions-by-file-component-tp5735152p5735188.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Custom logging of exceptions by file component

Posted by Nuno Santos <nf...@gmail.com>.
Thank you for all the answers. I solved the problem by adding an
errorHandler() to the route and disabling the logging with 

.logStackTrace(false).logExhausted(false)

Now I have a slightly different problem. When the upload to the server
fails, I want to increase exponentially the timeout between attempts. Does
the file component supports exponential backoff delays between polling for
files? I saw in the documentation that it is possible to specify a fixed
delay, but I couldn't find a way of specifying a different retry policy.

I saw that the retry policy for the redelivering exchanges support
exponential backoff, but doing the retry at the level of the route instead
of the file component creates another problem, which is that I can no longer
shutdown the process with CTRL^C. It seems that Camel delays the shutdown
while there are exchanges in transit. Is this correct? Is there some way
making Camel shutdown the server even if some routes have pending exchanges?
Or even better, to specify a shutdown handler for a route, so I can cleanup
pending exchanges?

Thank you,
Nuno



--
View this message in context: http://camel.465427.n5.nabble.com/Custom-logging-of-exceptions-by-file-component-tp5735152p5735186.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Custom logging of exceptions by file component

Posted by Claus Ibsen <cl...@gmail.com>.
You can configure the logging level and verbosity on the error handler
/ onException. So you can just turn off stacktrace and change from
ERROR to WARN or even OFF etc.



On Wed, Jul 3, 2013 at 5:51 PM, Nuno Santos <nf...@gmail.com> wrote:
> Hello everyone,
>
> I'm using the Camel File component to monitor a directory for any file
> written there and upload them to a server. Once a file is uploaded, it is
> moved to a different directory. If the upload attempt fails, the file is
> left in place and another attempt is made to upload it in the next poll
> cycle of the File component. The code looks like this:
>
> fromF("file://%s", directory)
>   .process(new Processor() {
>     @Override
>     public void process(Exchange exchange) throws Exception {
>       // try to upload to a web server. Throw exception if failed
>     });
>
> This is working fine except that whenever an upload fails, camel logs a
> message with a large stack trace. This means that every second or so the log
> files grow by a couple of hundreds of lines, which is not ideal. I want to
> do custom logging of this message, eg., print a single line with a short
> message for each attempt. But so far, I haven't found a way of doing this.
>
> If I add a custom error handler to the route above and mark the exception as
> handled, the file component thinks that everything succeeded and deletes the
> file. If I don't mark it as handled, the exception will still be logged by
> the file component after it rollsback. Is it possible to change the way that
> the File component logs these exceptions?
>
> Thank you advance
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Custom-logging-of-exceptions-by-file-component-tp5735152.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
www.camelone.org: The open source integration conference.

Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen