logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Scott Deboy" <sde...@comotivsystems.com>
Subject RE: Catching Log4j Exceptions
Date Tue, 04 Oct 2005 21:36:01 GMT
It looks like this appender will throw an exception (IllegalStateException) if you don't set
the 'remoteHost' property.  Of course, you'll probably get NPEs in other places if required
fields aren't specified on other appenders.

-----Original Message-----
From: Jacob Kjome [mailto:hoju@visi.com]
Sent: Tue 10/4/2005 2:31 PM
To: Log4J Users List
Subject: Re: Catching Log4j Exceptions
 

Oh, ok, the exception is printing to the console, but is not blowing up your
app.  Log4j is doing what it should.  It does not throw exceptions.  It
squashes them, but lets you know about it by printing the error.  The fix is to
either correct the Log4j configuration or, if the UDP address is proper, fix the
network configuration so that it can connect.  There is no exception to catch
because Log4j makes a promise not to throw them.  Imagine how ugly logging
would be if the logging utility itself threw exceptions!

Jake

Quoting illumine@speakeasy.net:

>
> I'm seeing this error in my junit testing.  I'm doing
> log.info(message).  Before this call I've attached a UDPAppender (with
> a "badhost") and removed all other appenders.
>
> /EA
>
> 3050 [main] ERROR org.apache.log4j.net.UDPAppender - Could not find
> address of [badhost].
> java.net.UnknownHostException: badhost: badhost
> 	at java.net.InetAddress.getAllByName0(InetAddress.java:1011)
> 	at java.net.InetAddress.getAllByName0(InetAddress.java:981)
> 	at java.net.InetAddress.getAllByName(InetAddress.java:975)
> 	at java.net.InetAddress.getByName(InetAddress.java:889)
> 	at
> org.apache.log4j.net.UDPAppender.getAddressByName(UDPAppender.java:227)
> 	at
> org.apache.log4j.net.UDPAppender.activateOptions(UDPAppender.java:122)
> 	at
> com.singingfish.knowledgebase.KBLogger.attachUDPAppender(KBLogger.java:
> 165)
> 	at com.singingfish.knowledgebase.KBLogger.<init>(KBLogger.java:96)
> 	at
> com.singingfish.knowledgebase.KBLogger$KBLoggerFunctionalTest.testMessag
> eNoServer(KBLogger.java:430)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav
> a:39)
> 	at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor
> Impl.java:25)
> 	at java.lang.reflect.Method.invoke(Method.java:324)
> 	at junit.framework.TestCase.runTest(TestCase.java:154)
> 	at junit.framework.TestCase.runBare(TestCase.java:127)
> 	at junit.framework.TestResult$1.protect(TestResult.java:106)
> 	at junit.framework.TestResult.runProtected(TestResult.java:124)
> 	at junit.framework.TestResult.run(TestResult.java:109)
> 	at junit.framework.TestCase.run(TestCase.java:118)
> 	at junit.framework.TestSuite.runTest(TestSuite.java:208)
> 	at junit.framework.TestSuite.run(TestSuite.java:203)
> 	at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTe
> stRunner.java:436)
> 	at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRun
> ner.java:311)
> 	at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRu
> nner.java:192)
>
>
> On Oct 4, 2005, at 1:50 PM, Jacob Kjome wrote:
>
> > Quoting illumine@speakeasy.net:
> >
> >> I have a question which has likely been answered (sorry, couldn't find
> >> it):  I'm using a UDPAppender so I want to be able to catch exceptions
> >> like UnknownHostException or BindException, but if I do...
> >>
> >> log.info("sending UDP message");
> >>
> >> and it fails, the Exception is sent to the console, but I'm not able
> >> to
> >> catch it in my code.  What is the intended way that I should handle
> >> these types of exceptions?
> >>
> >
> > Log4j should never ever throw exceptions from its public api.  What is
> > the
> > exception?  Please provide the stacktrace.
> >
> > Jake
> >
> >> Thanks for any help!
> >> /ErikAnthony
> >>
> >> p.s.
> >> If there is a wiki or FAQ that I should normally consult (other than
> >> the archive of this user list) that would be really helpful too.
> >> Thanks again!
> >> /EA
> >>
> >>
> >> ---------------------------------------------------------------------
> >> 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




Mime
View raw message