You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Nicholas Duane <ni...@msn.com> on 2016/01/13 22:38:05 UTC

Appender's append() method

I'm new to java so maybe this should be an obvious question to most java developers.  If I'm trying to override the append() method but also throw exceptions, how is that done?

I'm asking because I assume my append method's outermost catch block is to inspect the ignoreExceptions flag and either bubble up the exception if ignoreExceptions is false or eat the exception otherwise, most likely just logging an event.  Is that true?  If so, then how do I accomplish that?  I tried coding it as I mentioned above (actually someone else did it for me), but the compiler I guess was complaining about the throw needing to be in a catch block, I assume because the append() method is not defined to throw exceptions.

In addition, looking at what I think was source for one of your appenders at:

https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;a=blob;f=log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AbstractOutputStreamAppender.java;h=9a4cfde83194c866c30c4687e9f4ebb19cb20a17;hb=75d33d96ac00356014cf11f8ad9e8c6ead4db37a

Why does it always throw an exception in the catch block instead of checking the state of the ignoreExceptions flag?

Thanks,
Nick
 		 	   		  

Re: Appender's append() method

Posted by Ralph Goers <ra...@dslextreme.com>.
What compiler problem?  There is no compiler problem if a subclass of a RuntimeException is thrown. Appender’s shouldn’t be throwing checked exceptions.

Ralph

> On Jan 13, 2016, at 7:48 PM, Nicholas Duane <ni...@msn.com> wrote:
> 
> Thanks for the info.  What about the compiler problem which appears to be due to the fact that the append() method is not marked as throwing exceptions?
> 
> Thanks,
> Nick
> 
>> Date: Wed, 13 Jan 2016 14:17:47 -0800
>> Subject: Re: Appender's append() method
>> From: garydgregory@gmail.com
>> To: log4j-user@logging.apache.org
>> 
>> IMO a RuntimeException subclass is appropriate while RuntimeException
>> should not be used.
>> 
>> Gary
>> 
>> On Wed, Jan 13, 2016 at 1:53 PM, Ralph Goers <ra...@dslextreme.com>
>> wrote:
>> 
>>> Your appender is automatically wrapped by an AppenderControl object. The
>>> AppenderControl will inspect the ignoreExceptions flag so your Appender
>>> does not have to.  Your Appender should just throw a RuntimeException if it
>>> encounters a problem.
>>> 
>>> Ralph
>>> 
>>>> On Jan 13, 2016, at 2:38 PM, Nicholas Duane <ni...@msn.com> wrote:
>>>> 
>>>> I'm new to java so maybe this should be an obvious question to most java
>>> developers.  If I'm trying to override the append() method but also throw
>>> exceptions, how is that done?
>>>> 
>>>> I'm asking because I assume my append method's outermost catch block is
>>> to inspect the ignoreExceptions flag and either bubble up the exception if
>>> ignoreExceptions is false or eat the exception otherwise, most likely just
>>> logging an event.  Is that true?  If so, then how do I accomplish that?  I
>>> tried coding it as I mentioned above (actually someone else did it for me),
>>> but the compiler I guess was complaining about the throw needing to be in a
>>> catch block, I assume because the append() method is not defined to throw
>>> exceptions.
>>>> 
>>>> In addition, looking at what I think was source for one of your
>>> appenders at:
>>>> 
>>>> 
>>> https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;a=blob;f=log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AbstractOutputStreamAppender.java;h=9a4cfde83194c866c30c4687e9f4ebb19cb20a17;hb=75d33d96ac00356014cf11f8ad9e8c6ead4db37a
>>>> 
>>>> Why does it always throw an exception in the catch block instead of
>>> checking the state of the ignoreExceptions flag?
>>>> 
>>>> Thanks,
>>>> Nick
>>>> 
>>> 
>>> 
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>>> 
>>> 
>> 
>> 
>> -- 
>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>> Java Persistence with Hibernate, Second Edition
>> <http://www.manning.com/bauer3/>
>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>> Spring Batch in Action <http://www.manning.com/templier/>
>> Blog: http://garygregory.wordpress.com
>> Home: http://garygregory.com/
>> Tweet! http://twitter.com/GaryGregory
> 		 	   		  



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


RE: Appender's append() method

Posted by Nicholas Duane <ni...@msn.com>.
Thanks for the info.  What about the compiler problem which appears to be due to the fact that the append() method is not marked as throwing exceptions?

Thanks,
Nick

> Date: Wed, 13 Jan 2016 14:17:47 -0800
> Subject: Re: Appender's append() method
> From: garydgregory@gmail.com
> To: log4j-user@logging.apache.org
> 
> IMO a RuntimeException subclass is appropriate while RuntimeException
> should not be used.
> 
> Gary
> 
> On Wed, Jan 13, 2016 at 1:53 PM, Ralph Goers <ra...@dslextreme.com>
> wrote:
> 
> > Your appender is automatically wrapped by an AppenderControl object. The
> > AppenderControl will inspect the ignoreExceptions flag so your Appender
> > does not have to.  Your Appender should just throw a RuntimeException if it
> > encounters a problem.
> >
> > Ralph
> >
> > > On Jan 13, 2016, at 2:38 PM, Nicholas Duane <ni...@msn.com> wrote:
> > >
> > > I'm new to java so maybe this should be an obvious question to most java
> > developers.  If I'm trying to override the append() method but also throw
> > exceptions, how is that done?
> > >
> > > I'm asking because I assume my append method's outermost catch block is
> > to inspect the ignoreExceptions flag and either bubble up the exception if
> > ignoreExceptions is false or eat the exception otherwise, most likely just
> > logging an event.  Is that true?  If so, then how do I accomplish that?  I
> > tried coding it as I mentioned above (actually someone else did it for me),
> > but the compiler I guess was complaining about the throw needing to be in a
> > catch block, I assume because the append() method is not defined to throw
> > exceptions.
> > >
> > > In addition, looking at what I think was source for one of your
> > appenders at:
> > >
> > >
> > https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;a=blob;f=log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AbstractOutputStreamAppender.java;h=9a4cfde83194c866c30c4687e9f4ebb19cb20a17;hb=75d33d96ac00356014cf11f8ad9e8c6ead4db37a
> > >
> > > Why does it always throw an exception in the catch block instead of
> > checking the state of the ignoreExceptions flag?
> > >
> > > Thanks,
> > > Nick
> > >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> > For additional commands, e-mail: log4j-user-help@logging.apache.org
> >
> >
> 
> 
> -- 
> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> Java Persistence with Hibernate, Second Edition
> <http://www.manning.com/bauer3/>
> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> Spring Batch in Action <http://www.manning.com/templier/>
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
 		 	   		  

Re: Appender's append() method

Posted by Matt Sicker <bo...@gmail.com>.
You need to use a RuntimeException derivative. The whole point of not
swallowing Appender exceptions is that so something can be done based on
the exception. For instance, there's the FailoverAppender which lets you
switch to another Appender if the primary one starts to fail (e.g., network
connection down, out of disk space).

On 14 January 2016 at 20:08, Nicholas Duane <ni...@msn.com> wrote:

> I'm getting a little confused here.  I also left out some information.  We
> do need to catch because for some of our appenders we log the errors to
> loggers which will capture the errors in a central location.
>
> If we didn't include any exception handling that would mean any type of
> exception could be thrown back to the AppenderControl.  So if I do catch
> exceptions so that I can log them and then I want to rethrow them, is there
> a reason why I have to wrap them in some specific type of exception?
>
> Also, as I mentioned earlier, and unfortunately I didn't get a chance to
> test this yet but I believe I've seen this happen before, if I'm attempting
> to override a method which doesn't indicate it throws exceptions, won't the
> compiler complain if I attempt to throw an exception from that method?
>
> Thanks,
> Nick
>
> > Subject: Re: Appender's append() method
> > From: ralph.goers@dslextreme.com
> > Date: Wed, 13 Jan 2016 22:50:41 -0700
> > To: log4j-user@logging.apache.org
> >
> > Why are you catching it at all? AppenderControl also takes care of
> handling logging the exception so you don’t even have to catch the
> exception to do that.
> >
> > Ralph
> >
> > > On Jan 13, 2016, at 7:49 PM, Nicholas Duane <ni...@msn.com> wrote:
> > >
> > > Also, why would we not just rethrow whatever exception we caught?
> > >
> > > Thanks,
> > > Nick
> > >
> > >> Subject: Re: Appender's append() method
> > >> From: ralph.goers@dslextreme.com
> > >> Date: Wed, 13 Jan 2016 17:28:11 -0700
> > >> To: log4j-user@logging.apache.org
> > >>
> > >> Sorry, that was what I meant.
> > >>
> > >> Ralph
> > >>
> > >>> On Jan 13, 2016, at 3:17 PM, Gary Gregory <ga...@gmail.com>
> wrote:
> > >>>
> > >>> IMO a RuntimeException subclass is appropriate while RuntimeException
> > >>> should not be used.
> > >>>
> > >>> Gary
> > >>>
> > >>> On Wed, Jan 13, 2016 at 1:53 PM, Ralph Goers <
> ralph.goers@dslextreme.com>
> > >>> wrote:
> > >>>
> > >>>> Your appender is automatically wrapped by an AppenderControl
> object. The
> > >>>> AppenderControl will inspect the ignoreExceptions flag so your
> Appender
> > >>>> does not have to.  Your Appender should just throw a
> RuntimeException if it
> > >>>> encounters a problem.
> > >>>>
> > >>>> Ralph
> > >>>>
> > >>>>> On Jan 13, 2016, at 2:38 PM, Nicholas Duane <ni...@msn.com>
> wrote:
> > >>>>>
> > >>>>> I'm new to java so maybe this should be an obvious question to
> most java
> > >>>> developers.  If I'm trying to override the append() method but also
> throw
> > >>>> exceptions, how is that done?
> > >>>>>
> > >>>>> I'm asking because I assume my append method's outermost catch
> block is
> > >>>> to inspect the ignoreExceptions flag and either bubble up the
> exception if
> > >>>> ignoreExceptions is false or eat the exception otherwise, most
> likely just
> > >>>> logging an event.  Is that true?  If so, then how do I accomplish
> that?  I
> > >>>> tried coding it as I mentioned above (actually someone else did it
> for me),
> > >>>> but the compiler I guess was complaining about the throw needing to
> be in a
> > >>>> catch block, I assume because the append() method is not defined to
> throw
> > >>>> exceptions.
> > >>>>>
> > >>>>> In addition, looking at what I think was source for one of your
> > >>>> appenders at:
> > >>>>>
> > >>>>>
> > >>>>
> https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;a=blob;f=log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AbstractOutputStreamAppender.java;h=9a4cfde83194c866c30c4687e9f4ebb19cb20a17;hb=75d33d96ac00356014cf11f8ad9e8c6ead4db37a
> > >>>>>
> > >>>>> Why does it always throw an exception in the catch block instead of
> > >>>> checking the state of the ignoreExceptions flag?
> > >>>>>
> > >>>>> Thanks,
> > >>>>> Nick
> > >>>>>
> > >>>>
> > >>>>
> > >>>>
> > >>>>
> ---------------------------------------------------------------------
> > >>>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> > >>>> For additional commands, e-mail: log4j-user-help@logging.apache.org
> > >>>>
> > >>>>
> > >>>
> > >>>
> > >>> --
> > >>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> > >>> Java Persistence with Hibernate, Second Edition
> > >>> <http://www.manning.com/bauer3/>
> > >>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> > >>> Spring Batch in Action <http://www.manning.com/templier/>
> > >>> Blog: http://garygregory.wordpress.com
> > >>> Home: http://garygregory.com/
> > >>> Tweet! http://twitter.com/GaryGregory
> > >>
> > >>
> > >>
> > >> ---------------------------------------------------------------------
> > >> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> > >> For additional commands, e-mail: log4j-user-help@logging.apache.org
> > >>
> > >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> > For additional commands, e-mail: log4j-user-help@logging.apache.org
> >
>
>



-- 
Matt Sicker <bo...@gmail.com>

Re: Appender's append() method

Posted by Ralph Goers <ra...@dslextreme.com>.
Catch the exception, log it or whatever, then throw an AppenderLoggingException chaining the original exception to it.

Ralph

> On Jan 14, 2016, at 7:08 PM, Nicholas Duane <ni...@msn.com> wrote:
> 
> I'm getting a little confused here.  I also left out some information.  We do need to catch because for some of our appenders we log the errors to loggers which will capture the errors in a central location.
> 
> If we didn't include any exception handling that would mean any type of exception could be thrown back to the AppenderControl.  So if I do catch exceptions so that I can log them and then I want to rethrow them, is there a reason why I have to wrap them in some specific type of exception?
> 
> Also, as I mentioned earlier, and unfortunately I didn't get a chance to test this yet but I believe I've seen this happen before, if I'm attempting to override a method which doesn't indicate it throws exceptions, won't the compiler complain if I attempt to throw an exception from that method?
> 
> Thanks,
> Nick
> 
>> Subject: Re: Appender's append() method
>> From: ralph.goers@dslextreme.com
>> Date: Wed, 13 Jan 2016 22:50:41 -0700
>> To: log4j-user@logging.apache.org
>> 
>> Why are you catching it at all? AppenderControl also takes care of handling logging the exception so you don’t even have to catch the exception to do that.
>> 
>> Ralph
>> 
>>> On Jan 13, 2016, at 7:49 PM, Nicholas Duane <ni...@msn.com> wrote:
>>> 
>>> Also, why would we not just rethrow whatever exception we caught?
>>> 
>>> Thanks,
>>> Nick
>>> 
>>>> Subject: Re: Appender's append() method
>>>> From: ralph.goers@dslextreme.com
>>>> Date: Wed, 13 Jan 2016 17:28:11 -0700
>>>> To: log4j-user@logging.apache.org
>>>> 
>>>> Sorry, that was what I meant.
>>>> 
>>>> Ralph
>>>> 
>>>>> On Jan 13, 2016, at 3:17 PM, Gary Gregory <ga...@gmail.com> wrote:
>>>>> 
>>>>> IMO a RuntimeException subclass is appropriate while RuntimeException
>>>>> should not be used.
>>>>> 
>>>>> Gary
>>>>> 
>>>>> On Wed, Jan 13, 2016 at 1:53 PM, Ralph Goers <ra...@dslextreme.com>
>>>>> wrote:
>>>>> 
>>>>>> Your appender is automatically wrapped by an AppenderControl object. The
>>>>>> AppenderControl will inspect the ignoreExceptions flag so your Appender
>>>>>> does not have to.  Your Appender should just throw a RuntimeException if it
>>>>>> encounters a problem.
>>>>>> 
>>>>>> Ralph
>>>>>> 
>>>>>>> On Jan 13, 2016, at 2:38 PM, Nicholas Duane <ni...@msn.com> wrote:
>>>>>>> 
>>>>>>> I'm new to java so maybe this should be an obvious question to most java
>>>>>> developers.  If I'm trying to override the append() method but also throw
>>>>>> exceptions, how is that done?
>>>>>>> 
>>>>>>> I'm asking because I assume my append method's outermost catch block is
>>>>>> to inspect the ignoreExceptions flag and either bubble up the exception if
>>>>>> ignoreExceptions is false or eat the exception otherwise, most likely just
>>>>>> logging an event.  Is that true?  If so, then how do I accomplish that?  I
>>>>>> tried coding it as I mentioned above (actually someone else did it for me),
>>>>>> but the compiler I guess was complaining about the throw needing to be in a
>>>>>> catch block, I assume because the append() method is not defined to throw
>>>>>> exceptions.
>>>>>>> 
>>>>>>> In addition, looking at what I think was source for one of your
>>>>>> appenders at:
>>>>>>> 
>>>>>>> 
>>>>>> https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;a=blob;f=log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AbstractOutputStreamAppender.java;h=9a4cfde83194c866c30c4687e9f4ebb19cb20a17;hb=75d33d96ac00356014cf11f8ad9e8c6ead4db37a
>>>>>>> 
>>>>>>> Why does it always throw an exception in the catch block instead of
>>>>>> checking the state of the ignoreExceptions flag?
>>>>>>> 
>>>>>>> Thanks,
>>>>>>> Nick
>>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>>>>>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>>>>>> 
>>>>>> 
>>>>> 
>>>>> 
>>>>> -- 
>>>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>>>> Java Persistence with Hibernate, Second Edition
>>>>> <http://www.manning.com/bauer3/>
>>>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>>>> Spring Batch in Action <http://www.manning.com/templier/>
>>>>> Blog: http://garygregory.wordpress.com
>>>>> Home: http://garygregory.com/
>>>>> Tweet! http://twitter.com/GaryGregory
>>>> 
>>>> 
>>>> 
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>>>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>>>> 
>>> 		 	   		  
>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>> 
> 		 	   		  



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


RE: Appender's append() method

Posted by Nicholas Duane <ni...@msn.com>.
I'm getting a little confused here.  I also left out some information.  We do need to catch because for some of our appenders we log the errors to loggers which will capture the errors in a central location.

If we didn't include any exception handling that would mean any type of exception could be thrown back to the AppenderControl.  So if I do catch exceptions so that I can log them and then I want to rethrow them, is there a reason why I have to wrap them in some specific type of exception?

Also, as I mentioned earlier, and unfortunately I didn't get a chance to test this yet but I believe I've seen this happen before, if I'm attempting to override a method which doesn't indicate it throws exceptions, won't the compiler complain if I attempt to throw an exception from that method?

Thanks,
Nick

> Subject: Re: Appender's append() method
> From: ralph.goers@dslextreme.com
> Date: Wed, 13 Jan 2016 22:50:41 -0700
> To: log4j-user@logging.apache.org
> 
> Why are you catching it at all? AppenderControl also takes care of handling logging the exception so you don’t even have to catch the exception to do that.
> 
> Ralph
> 
> > On Jan 13, 2016, at 7:49 PM, Nicholas Duane <ni...@msn.com> wrote:
> > 
> > Also, why would we not just rethrow whatever exception we caught?
> > 
> > Thanks,
> > Nick
> > 
> >> Subject: Re: Appender's append() method
> >> From: ralph.goers@dslextreme.com
> >> Date: Wed, 13 Jan 2016 17:28:11 -0700
> >> To: log4j-user@logging.apache.org
> >> 
> >> Sorry, that was what I meant.
> >> 
> >> Ralph
> >> 
> >>> On Jan 13, 2016, at 3:17 PM, Gary Gregory <ga...@gmail.com> wrote:
> >>> 
> >>> IMO a RuntimeException subclass is appropriate while RuntimeException
> >>> should not be used.
> >>> 
> >>> Gary
> >>> 
> >>> On Wed, Jan 13, 2016 at 1:53 PM, Ralph Goers <ra...@dslextreme.com>
> >>> wrote:
> >>> 
> >>>> Your appender is automatically wrapped by an AppenderControl object. The
> >>>> AppenderControl will inspect the ignoreExceptions flag so your Appender
> >>>> does not have to.  Your Appender should just throw a RuntimeException if it
> >>>> encounters a problem.
> >>>> 
> >>>> Ralph
> >>>> 
> >>>>> On Jan 13, 2016, at 2:38 PM, Nicholas Duane <ni...@msn.com> wrote:
> >>>>> 
> >>>>> I'm new to java so maybe this should be an obvious question to most java
> >>>> developers.  If I'm trying to override the append() method but also throw
> >>>> exceptions, how is that done?
> >>>>> 
> >>>>> I'm asking because I assume my append method's outermost catch block is
> >>>> to inspect the ignoreExceptions flag and either bubble up the exception if
> >>>> ignoreExceptions is false or eat the exception otherwise, most likely just
> >>>> logging an event.  Is that true?  If so, then how do I accomplish that?  I
> >>>> tried coding it as I mentioned above (actually someone else did it for me),
> >>>> but the compiler I guess was complaining about the throw needing to be in a
> >>>> catch block, I assume because the append() method is not defined to throw
> >>>> exceptions.
> >>>>> 
> >>>>> In addition, looking at what I think was source for one of your
> >>>> appenders at:
> >>>>> 
> >>>>> 
> >>>> https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;a=blob;f=log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AbstractOutputStreamAppender.java;h=9a4cfde83194c866c30c4687e9f4ebb19cb20a17;hb=75d33d96ac00356014cf11f8ad9e8c6ead4db37a
> >>>>> 
> >>>>> Why does it always throw an exception in the catch block instead of
> >>>> checking the state of the ignoreExceptions flag?
> >>>>> 
> >>>>> Thanks,
> >>>>> Nick
> >>>>> 
> >>>> 
> >>>> 
> >>>> 
> >>>> ---------------------------------------------------------------------
> >>>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> >>>> For additional commands, e-mail: log4j-user-help@logging.apache.org
> >>>> 
> >>>> 
> >>> 
> >>> 
> >>> -- 
> >>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> >>> Java Persistence with Hibernate, Second Edition
> >>> <http://www.manning.com/bauer3/>
> >>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> >>> Spring Batch in Action <http://www.manning.com/templier/>
> >>> Blog: http://garygregory.wordpress.com
> >>> Home: http://garygregory.com/
> >>> Tweet! http://twitter.com/GaryGregory
> >> 
> >> 
> >> 
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> >> For additional commands, e-mail: log4j-user-help@logging.apache.org
> >> 
> > 		 	   		  
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
> 
 		 	   		  

Re: Appender's append() method

Posted by Mikael Ståldal <mi...@magine.com>.
I might be a good idea to allow Appenders to throw any exception. Having to
catch and wrap checked exceptions is annoying.

On Thu, Jan 14, 2016 at 6:50 AM, Ralph Goers <ra...@dslextreme.com>
wrote:

> Why are you catching it at all? AppenderControl also takes care of
> handling logging the exception so you don’t even have to catch the
> exception to do that.
>
> Ralph
>
> > On Jan 13, 2016, at 7:49 PM, Nicholas Duane <ni...@msn.com> wrote:
> >
> > Also, why would we not just rethrow whatever exception we caught?
> >
> > Thanks,
> > Nick
> >
> >> Subject: Re: Appender's append() method
> >> From: ralph.goers@dslextreme.com
> >> Date: Wed, 13 Jan 2016 17:28:11 -0700
> >> To: log4j-user@logging.apache.org
> >>
> >> Sorry, that was what I meant.
> >>
> >> Ralph
> >>
> >>> On Jan 13, 2016, at 3:17 PM, Gary Gregory <ga...@gmail.com>
> wrote:
> >>>
> >>> IMO a RuntimeException subclass is appropriate while RuntimeException
> >>> should not be used.
> >>>
> >>> Gary
> >>>
> >>> On Wed, Jan 13, 2016 at 1:53 PM, Ralph Goers <
> ralph.goers@dslextreme.com>
> >>> wrote:
> >>>
> >>>> Your appender is automatically wrapped by an AppenderControl object.
> The
> >>>> AppenderControl will inspect the ignoreExceptions flag so your
> Appender
> >>>> does not have to.  Your Appender should just throw a RuntimeException
> if it
> >>>> encounters a problem.
> >>>>
> >>>> Ralph
> >>>>
> >>>>> On Jan 13, 2016, at 2:38 PM, Nicholas Duane <ni...@msn.com> wrote:
> >>>>>
> >>>>> I'm new to java so maybe this should be an obvious question to most
> java
> >>>> developers.  If I'm trying to override the append() method but also
> throw
> >>>> exceptions, how is that done?
> >>>>>
> >>>>> I'm asking because I assume my append method's outermost catch block
> is
> >>>> to inspect the ignoreExceptions flag and either bubble up the
> exception if
> >>>> ignoreExceptions is false or eat the exception otherwise, most likely
> just
> >>>> logging an event.  Is that true?  If so, then how do I accomplish
> that?  I
> >>>> tried coding it as I mentioned above (actually someone else did it
> for me),
> >>>> but the compiler I guess was complaining about the throw needing to
> be in a
> >>>> catch block, I assume because the append() method is not defined to
> throw
> >>>> exceptions.
> >>>>>
> >>>>> In addition, looking at what I think was source for one of your
> >>>> appenders at:
> >>>>>
> >>>>>
> >>>>
> https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;a=blob;f=log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AbstractOutputStreamAppender.java;h=9a4cfde83194c866c30c4687e9f4ebb19cb20a17;hb=75d33d96ac00356014cf11f8ad9e8c6ead4db37a
> >>>>>
> >>>>> Why does it always throw an exception in the catch block instead of
> >>>> checking the state of the ignoreExceptions flag?
> >>>>>
> >>>>> Thanks,
> >>>>> Nick
> >>>>>
> >>>>
> >>>>
> >>>>
> >>>> ---------------------------------------------------------------------
> >>>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> >>>> For additional commands, e-mail: log4j-user-help@logging.apache.org
> >>>>
> >>>>
> >>>
> >>>
> >>> --
> >>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> >>> Java Persistence with Hibernate, Second Edition
> >>> <http://www.manning.com/bauer3/>
> >>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> >>> Spring Batch in Action <http://www.manning.com/templier/>
> >>> Blog: http://garygregory.wordpress.com
> >>> Home: http://garygregory.com/
> >>> Tweet! http://twitter.com/GaryGregory
> >>
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> >> For additional commands, e-mail: log4j-user-help@logging.apache.org
> >>
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>


-- 
[image: MagineTV]

*Mikael Ståldal*
Senior software developer

*Magine TV*
mikael.staldal@magine.com
Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com

Privileged and/or Confidential Information may be contained in this
message. If you are not the addressee indicated in this message
(or responsible for delivery of the message to such a person), you may not
copy or deliver this message to anyone. In such case,
you should destroy this message and kindly notify the sender by reply
email.

Re: Appender's append() method

Posted by Ralph Goers <ra...@dslextreme.com>.
Why are you catching it at all? AppenderControl also takes care of handling logging the exception so you don’t even have to catch the exception to do that.

Ralph

> On Jan 13, 2016, at 7:49 PM, Nicholas Duane <ni...@msn.com> wrote:
> 
> Also, why would we not just rethrow whatever exception we caught?
> 
> Thanks,
> Nick
> 
>> Subject: Re: Appender's append() method
>> From: ralph.goers@dslextreme.com
>> Date: Wed, 13 Jan 2016 17:28:11 -0700
>> To: log4j-user@logging.apache.org
>> 
>> Sorry, that was what I meant.
>> 
>> Ralph
>> 
>>> On Jan 13, 2016, at 3:17 PM, Gary Gregory <ga...@gmail.com> wrote:
>>> 
>>> IMO a RuntimeException subclass is appropriate while RuntimeException
>>> should not be used.
>>> 
>>> Gary
>>> 
>>> On Wed, Jan 13, 2016 at 1:53 PM, Ralph Goers <ra...@dslextreme.com>
>>> wrote:
>>> 
>>>> Your appender is automatically wrapped by an AppenderControl object. The
>>>> AppenderControl will inspect the ignoreExceptions flag so your Appender
>>>> does not have to.  Your Appender should just throw a RuntimeException if it
>>>> encounters a problem.
>>>> 
>>>> Ralph
>>>> 
>>>>> On Jan 13, 2016, at 2:38 PM, Nicholas Duane <ni...@msn.com> wrote:
>>>>> 
>>>>> I'm new to java so maybe this should be an obvious question to most java
>>>> developers.  If I'm trying to override the append() method but also throw
>>>> exceptions, how is that done?
>>>>> 
>>>>> I'm asking because I assume my append method's outermost catch block is
>>>> to inspect the ignoreExceptions flag and either bubble up the exception if
>>>> ignoreExceptions is false or eat the exception otherwise, most likely just
>>>> logging an event.  Is that true?  If so, then how do I accomplish that?  I
>>>> tried coding it as I mentioned above (actually someone else did it for me),
>>>> but the compiler I guess was complaining about the throw needing to be in a
>>>> catch block, I assume because the append() method is not defined to throw
>>>> exceptions.
>>>>> 
>>>>> In addition, looking at what I think was source for one of your
>>>> appenders at:
>>>>> 
>>>>> 
>>>> https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;a=blob;f=log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AbstractOutputStreamAppender.java;h=9a4cfde83194c866c30c4687e9f4ebb19cb20a17;hb=75d33d96ac00356014cf11f8ad9e8c6ead4db37a
>>>>> 
>>>>> Why does it always throw an exception in the catch block instead of
>>>> checking the state of the ignoreExceptions flag?
>>>>> 
>>>>> Thanks,
>>>>> Nick
>>>>> 
>>>> 
>>>> 
>>>> 
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>>>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>>>> 
>>>> 
>>> 
>>> 
>>> -- 
>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>> Java Persistence with Hibernate, Second Edition
>>> <http://www.manning.com/bauer3/>
>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>> Spring Batch in Action <http://www.manning.com/templier/>
>>> Blog: http://garygregory.wordpress.com
>>> Home: http://garygregory.com/
>>> Tweet! http://twitter.com/GaryGregory
>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>> 
> 		 	   		  



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


RE: Appender's append() method

Posted by Nicholas Duane <ni...@msn.com>.
Also, why would we not just rethrow whatever exception we caught?

Thanks,
Nick

> Subject: Re: Appender's append() method
> From: ralph.goers@dslextreme.com
> Date: Wed, 13 Jan 2016 17:28:11 -0700
> To: log4j-user@logging.apache.org
> 
> Sorry, that was what I meant.
> 
> Ralph
> 
> > On Jan 13, 2016, at 3:17 PM, Gary Gregory <ga...@gmail.com> wrote:
> > 
> > IMO a RuntimeException subclass is appropriate while RuntimeException
> > should not be used.
> > 
> > Gary
> > 
> > On Wed, Jan 13, 2016 at 1:53 PM, Ralph Goers <ra...@dslextreme.com>
> > wrote:
> > 
> >> Your appender is automatically wrapped by an AppenderControl object. The
> >> AppenderControl will inspect the ignoreExceptions flag so your Appender
> >> does not have to.  Your Appender should just throw a RuntimeException if it
> >> encounters a problem.
> >> 
> >> Ralph
> >> 
> >>> On Jan 13, 2016, at 2:38 PM, Nicholas Duane <ni...@msn.com> wrote:
> >>> 
> >>> I'm new to java so maybe this should be an obvious question to most java
> >> developers.  If I'm trying to override the append() method but also throw
> >> exceptions, how is that done?
> >>> 
> >>> I'm asking because I assume my append method's outermost catch block is
> >> to inspect the ignoreExceptions flag and either bubble up the exception if
> >> ignoreExceptions is false or eat the exception otherwise, most likely just
> >> logging an event.  Is that true?  If so, then how do I accomplish that?  I
> >> tried coding it as I mentioned above (actually someone else did it for me),
> >> but the compiler I guess was complaining about the throw needing to be in a
> >> catch block, I assume because the append() method is not defined to throw
> >> exceptions.
> >>> 
> >>> In addition, looking at what I think was source for one of your
> >> appenders at:
> >>> 
> >>> 
> >> https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;a=blob;f=log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AbstractOutputStreamAppender.java;h=9a4cfde83194c866c30c4687e9f4ebb19cb20a17;hb=75d33d96ac00356014cf11f8ad9e8c6ead4db37a
> >>> 
> >>> Why does it always throw an exception in the catch block instead of
> >> checking the state of the ignoreExceptions flag?
> >>> 
> >>> Thanks,
> >>> Nick
> >>> 
> >> 
> >> 
> >> 
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> >> For additional commands, e-mail: log4j-user-help@logging.apache.org
> >> 
> >> 
> > 
> > 
> > -- 
> > E-Mail: garydgregory@gmail.com | ggregory@apache.org
> > Java Persistence with Hibernate, Second Edition
> > <http://www.manning.com/bauer3/>
> > JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> > Spring Batch in Action <http://www.manning.com/templier/>
> > Blog: http://garygregory.wordpress.com
> > Home: http://garygregory.com/
> > Tweet! http://twitter.com/GaryGregory
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
> 
 		 	   		  

Re: Appender's append() method

Posted by Ralph Goers <ra...@dslextreme.com>.
Sorry, that was what I meant.

Ralph

> On Jan 13, 2016, at 3:17 PM, Gary Gregory <ga...@gmail.com> wrote:
> 
> IMO a RuntimeException subclass is appropriate while RuntimeException
> should not be used.
> 
> Gary
> 
> On Wed, Jan 13, 2016 at 1:53 PM, Ralph Goers <ra...@dslextreme.com>
> wrote:
> 
>> Your appender is automatically wrapped by an AppenderControl object. The
>> AppenderControl will inspect the ignoreExceptions flag so your Appender
>> does not have to.  Your Appender should just throw a RuntimeException if it
>> encounters a problem.
>> 
>> Ralph
>> 
>>> On Jan 13, 2016, at 2:38 PM, Nicholas Duane <ni...@msn.com> wrote:
>>> 
>>> I'm new to java so maybe this should be an obvious question to most java
>> developers.  If I'm trying to override the append() method but also throw
>> exceptions, how is that done?
>>> 
>>> I'm asking because I assume my append method's outermost catch block is
>> to inspect the ignoreExceptions flag and either bubble up the exception if
>> ignoreExceptions is false or eat the exception otherwise, most likely just
>> logging an event.  Is that true?  If so, then how do I accomplish that?  I
>> tried coding it as I mentioned above (actually someone else did it for me),
>> but the compiler I guess was complaining about the throw needing to be in a
>> catch block, I assume because the append() method is not defined to throw
>> exceptions.
>>> 
>>> In addition, looking at what I think was source for one of your
>> appenders at:
>>> 
>>> 
>> https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;a=blob;f=log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AbstractOutputStreamAppender.java;h=9a4cfde83194c866c30c4687e9f4ebb19cb20a17;hb=75d33d96ac00356014cf11f8ad9e8c6ead4db37a
>>> 
>>> Why does it always throw an exception in the catch block instead of
>> checking the state of the ignoreExceptions flag?
>>> 
>>> Thanks,
>>> Nick
>>> 
>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>> 
>> 
> 
> 
> -- 
> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> Java Persistence with Hibernate, Second Edition
> <http://www.manning.com/bauer3/>
> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> Spring Batch in Action <http://www.manning.com/templier/>
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Appender's append() method

Posted by Gary Gregory <ga...@gmail.com>.
IMO a RuntimeException subclass is appropriate while RuntimeException
should not be used.

Gary

On Wed, Jan 13, 2016 at 1:53 PM, Ralph Goers <ra...@dslextreme.com>
wrote:

> Your appender is automatically wrapped by an AppenderControl object. The
> AppenderControl will inspect the ignoreExceptions flag so your Appender
> does not have to.  Your Appender should just throw a RuntimeException if it
> encounters a problem.
>
> Ralph
>
> > On Jan 13, 2016, at 2:38 PM, Nicholas Duane <ni...@msn.com> wrote:
> >
> > I'm new to java so maybe this should be an obvious question to most java
> developers.  If I'm trying to override the append() method but also throw
> exceptions, how is that done?
> >
> > I'm asking because I assume my append method's outermost catch block is
> to inspect the ignoreExceptions flag and either bubble up the exception if
> ignoreExceptions is false or eat the exception otherwise, most likely just
> logging an event.  Is that true?  If so, then how do I accomplish that?  I
> tried coding it as I mentioned above (actually someone else did it for me),
> but the compiler I guess was complaining about the throw needing to be in a
> catch block, I assume because the append() method is not defined to throw
> exceptions.
> >
> > In addition, looking at what I think was source for one of your
> appenders at:
> >
> >
> https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;a=blob;f=log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AbstractOutputStreamAppender.java;h=9a4cfde83194c866c30c4687e9f4ebb19cb20a17;hb=75d33d96ac00356014cf11f8ad9e8c6ead4db37a
> >
> > Why does it always throw an exception in the catch block instead of
> checking the state of the ignoreExceptions flag?
> >
> > Thanks,
> > Nick
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>


-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Re: Appender's append() method

Posted by Mikael Ståldal <mi...@magine.com>.
I guess that AppenderLoggingException can be used for that purpose.

On Wed, Jan 13, 2016 at 10:53 PM, Ralph Goers <ra...@dslextreme.com>
wrote:

> Your appender is automatically wrapped by an AppenderControl object. The
> AppenderControl will inspect the ignoreExceptions flag so your Appender
> does not have to.  Your Appender should just throw a RuntimeException if it
> encounters a problem.
>
> Ralph
>
> > On Jan 13, 2016, at 2:38 PM, Nicholas Duane <ni...@msn.com> wrote:
> >
> > I'm new to java so maybe this should be an obvious question to most java
> developers.  If I'm trying to override the append() method but also throw
> exceptions, how is that done?
> >
> > I'm asking because I assume my append method's outermost catch block is
> to inspect the ignoreExceptions flag and either bubble up the exception if
> ignoreExceptions is false or eat the exception otherwise, most likely just
> logging an event.  Is that true?  If so, then how do I accomplish that?  I
> tried coding it as I mentioned above (actually someone else did it for me),
> but the compiler I guess was complaining about the throw needing to be in a
> catch block, I assume because the append() method is not defined to throw
> exceptions.
> >
> > In addition, looking at what I think was source for one of your
> appenders at:
> >
> >
> https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;a=blob;f=log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AbstractOutputStreamAppender.java;h=9a4cfde83194c866c30c4687e9f4ebb19cb20a17;hb=75d33d96ac00356014cf11f8ad9e8c6ead4db37a
> >
> > Why does it always throw an exception in the catch block instead of
> checking the state of the ignoreExceptions flag?
> >
> > Thanks,
> > Nick
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>


-- 
[image: MagineTV]

*Mikael Ståldal*
Senior software developer

*Magine TV*
mikael.staldal@magine.com
Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com

Privileged and/or Confidential Information may be contained in this
message. If you are not the addressee indicated in this message
(or responsible for delivery of the message to such a person), you may not
copy or deliver this message to anyone. In such case,
you should destroy this message and kindly notify the sender by reply
email.

Re: Appender's append() method

Posted by Ralph Goers <ra...@dslextreme.com>.
Your appender is automatically wrapped by an AppenderControl object. The AppenderControl will inspect the ignoreExceptions flag so your Appender does not have to.  Your Appender should just throw a RuntimeException if it encounters a problem.

Ralph 

> On Jan 13, 2016, at 2:38 PM, Nicholas Duane <ni...@msn.com> wrote:
> 
> I'm new to java so maybe this should be an obvious question to most java developers.  If I'm trying to override the append() method but also throw exceptions, how is that done?
> 
> I'm asking because I assume my append method's outermost catch block is to inspect the ignoreExceptions flag and either bubble up the exception if ignoreExceptions is false or eat the exception otherwise, most likely just logging an event.  Is that true?  If so, then how do I accomplish that?  I tried coding it as I mentioned above (actually someone else did it for me), but the compiler I guess was complaining about the throw needing to be in a catch block, I assume because the append() method is not defined to throw exceptions.
> 
> In addition, looking at what I think was source for one of your appenders at:
> 
> https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;a=blob;f=log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AbstractOutputStreamAppender.java;h=9a4cfde83194c866c30c4687e9f4ebb19cb20a17;hb=75d33d96ac00356014cf11f8ad9e8c6ead4db37a
> 
> Why does it always throw an exception in the catch block instead of checking the state of the ignoreExceptions flag?
> 
> Thanks,
> Nick
> 		 	   		  



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org