You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by "Sam Beroz (JIRA)" <ji...@apache.org> on 2014/11/17 18:23:34 UTC
[jira] [Created] (LOG4J2-894) AsyncAppender throws
ConfigurationException when wrapped SyslogAppender fails
Sam Beroz created LOG4J2-894:
--------------------------------
Summary: AsyncAppender throws ConfigurationException when wrapped SyslogAppender fails
Key: LOG4J2-894
URL: https://issues.apache.org/jira/browse/LOG4J2-894
Project: Log4j 2
Issue Type: Bug
Affects Versions: 2.1
Environment: All
Reporter: Sam Beroz
Priority: Minor
I'd like a way to create AsyncAppender and have it not throw if the appender it wraps is unavailable. My work around is to always also include an appender that I know to be available.
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 loose 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 reportingthat "No appenders are available for AsyncAppender", killing my whole application.
From: org/apache/logging/log4j/core/appender/AsyncAppender.java
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>
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org