Reputation: 11363
I have an application that has the logger configured to send emails to all application administrators if a marker is set. We wrote a custom email appender to do so, since the existing SMTPAppender was too inflexible for our needs.
Earlier this week, we noticed that logging emails were not being received from our QA server, which were a regular occurrence before. There is nothing in our config that pops out at me, and I'm pretty stumped.
This is the output from application start in the IDE:
2015-10-07 14:26:11,344 ERROR Error processing element EMAIL: CLASS_NOT_FOUND
2015-10-07 14:26:11,435 ERROR Unable to locate appender Email for logger
14:26:11.709 [main] INFO c.q.app.services.server.data.h2.H2DbLifecycleManager - Starting DB on
connection jdbc:h2:tcp://localhost/C:/Users/jason/AppData/Local/appserver/store/data/db
2015-10-07 14:26:13,401 ERROR Error processing element EMAIL: CLASS_NOT_FOUND
2015-10-07 14:26:13,416 ERROR Unable to locate appender Email for logger
Oct 07, 2015 2:26:14 PM org.hibernate.validator.internal.util.Version <clinit>
INFO: HV000001: Hibernate Validator 4.3.1.Final
That Email appender is defined in the configuration below within the EMAIL
block. The configuration in log4j.xml is
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
<EMAIL name="Email">
<PatternLayout pattern="%d{MMM dd, yyyy - HH:mm:ss}%n%msg%n"/>
<MarkerFilter marker="NOTIFICATION_EMAIL" onMatch="ACCEPT" onMismatch="DENY"/>
</EMAIL>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="Console"/>
<AppenderRef ref="Email"/>
</Root>
<Logger name="com.ning.http.client" level="warn">
<AppenderRef ref="Console" />
</Logger>
</Loggers>
</Configuration>
and the custom appender is defined as
/**
* An appender used to send an email notification of a log event to all application Administrators.
*/
@Plugin(name = "EMAIL", category = "Core", elementType = "appender", printObject = true)
public class EmailAppender extends AbstractAppender
{
/**
* @param name - the name of the Appender. Cannot be null
* @param filter - The Filter or null (defaults to ThresholdFilter, level of ERROR).
* @param layout - The layout to use - if not included it uses the default PatternLayout.
* @return an appender for sending emails on logging events
*/
@PluginFactory
public static EmailAppender createAppender(@PluginAttribute("name") final String name,
@PluginElement("Filter") Filter filter, @PluginElement("Layout") Layout<? extends Serializable> layout)
{
if (name == null)
{
LOGGER.error("No name provided for NotificationAppender");
return null;
}
if (filter == null)
filter = ThresholdFilter.createFilter(null, null, null);
if (layout == null)
layout = PatternLayout.createDefaultLayout();
return new EmailAppender(name, filter, layout);
}
protected EmailAppender(String name, Filter filter, Layout<? extends Serializable> layout)
{
super(name, filter, layout);
}
...
}
Everything seems to be configured as expected. However, for an unknown reason, EmailAppender is not being compiled or included in the build at all. Any thoughts how to resolve this?
Upvotes: 1
Views: 325
Reputation: 11363
Posting this answer in case anyone comes across a similar situation.
For an unknown reason, the Log4J annotation scanner wasn't able to pick up the custom appender class, despite the `@Plugin(name=...) annotation on the class definition. I don't have the experience or tools to dig down into the reasons why, but came across a solution.
Adding a packages
qualifier to the Configuration
tag did the trick, like so:
<Configuration status="WARN" packages="com.company.web.common.logging">
Upvotes: 1