I've got a SyslogAppender that sends logs to a remote EC2 box and I've
wrapped it in an AsyncAppender. The log traffic's is just to monitor the
state of the application and it's ok if it's not sent should the machine
running it lose its' internet connection or if Amazon goes down.
When I set the SyslogAppender's host to a fake URL I had expected it to
fail gracefully but instead when I call LogManager.getLogger()
the AsyncAppender threw a ConfigurationException, killing my whole
application:
104 } else if (errorRef == null) {105 throw
new ConfigurationException("No appenders are available for
AsyncAppender " + getName());106 }
Looking at the source I thought I could avoid this by adding my
ConsoleAppender as an errorRef but that results in a NullPointerException
on startup because I still have zero appenders so start is called on the
uninitialized thread:
101 if (appenders.size() > 0) {102 thread =
new AsyncThread(appenders, queue);103
thread.setName("AsyncAppender-" + getName());104 } else if
(errorRef == null) {105 throw new
ConfigurationException("No appenders are available for AsyncAppender "
+ getName());106 }107 108 thread.start();
I was able to work around this by also including my ConsoleAppender in the
AsyncAppender so it always contains at least one valid appender:
<!-- The AsyncAppender will throw a Configuration Exception if it can't
send data anywhere -->
<Async name="Async" blocking="false" includeLocation="true">
<AppenderRef ref="SYSLOG"/>
<AppenderRef ref="CONSOLE"/>
</Async>
I don't know if there is a better way to do this. In any event, I thought I
share what I found. Thanks - Sam