Package com.github.akunzai.log4j
Class SendGridAppender
- java.lang.Object
-
- org.apache.logging.log4j.core.AbstractLifeCycle
-
- org.apache.logging.log4j.core.filter.AbstractFilterable
-
- org.apache.logging.log4j.core.appender.AbstractAppender
-
- com.github.akunzai.log4j.SendGridAppender
-
- All Implemented Interfaces:
org.apache.logging.log4j.core.Appender,org.apache.logging.log4j.core.filter.Filterable,org.apache.logging.log4j.core.impl.LocationAware,org.apache.logging.log4j.core.LifeCycle,org.apache.logging.log4j.core.LifeCycle2
@Plugin(name="SendGrid", category="Core", elementType="appender", printObject=true) public class SendGridAppender extends org.apache.logging.log4j.core.appender.AbstractAppenderSend an e-mail when a specific logging event occurs, typically on errors or fatal errors.The number of logging events delivered in this e-mail depend on the value of BufferSize option. The
SendGridAppenderkeeps only the lastBufferSizelogging events in its cyclic buffer. This keeps memory requirements at a reasonable level while still delivering useful application context.By default, an email message will format as HTML. This can be modified by setting a layout for the appender.
By default, an email message will be sent when an ERROR or higher severity message is appended. This can be modified by setting a filter for the appender.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSendGridAppender.BuilderThe Plugin Builder for SendGridAppender
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidappend(org.apache.logging.log4j.core.LogEvent event)Perform SendGridAppender specific appending actions, mainly adding the event to a cyclic buffer and checking if the event triggers an e-mail to be sent.static SendGridAppendercreateAppender(org.apache.logging.log4j.core.config.Configuration config, java.lang.String name, java.lang.String to, java.lang.String cc, java.lang.String bcc, java.lang.String from, java.lang.String replyTo, java.lang.String subject, java.lang.String host, java.lang.String apiKey, java.lang.String sandboxMode, java.lang.String bufferSize, org.apache.logging.log4j.core.Layout<? extends java.io.Serializable> layout, org.apache.logging.log4j.core.Filter filter, java.lang.String ignore)Deprecated.UsenewBuilder()to create and configure aSendGridAppender.Builderinstance.booleanisFiltered(org.apache.logging.log4j.core.LogEvent event)Capture all events in CyclicBuffer.static SendGridAppender.BuildernewBuilder()Create a Plugin Builder for SendGridAppender-
Methods inherited from class org.apache.logging.log4j.core.appender.AbstractAppender
error, error, error, getHandler, getLayout, getName, ignoreExceptions, parseInt, requiresLocation, setHandler, toSerializable, toString
-
Methods inherited from class org.apache.logging.log4j.core.filter.AbstractFilterable
addFilter, getFilter, getPropertyArray, hasFilter, removeFilter, start, stop, stop
-
Methods inherited from class org.apache.logging.log4j.core.AbstractLifeCycle
equalsImpl, getState, getStatusLogger, hashCodeImpl, initialize, isInitialized, isStarted, isStarting, isStopped, isStopping, setStarted, setStarting, setState, setStopped, setStopping, stop, stop
-
-
-
-
Method Detail
-
newBuilder
@PluginBuilderFactory public static SendGridAppender.Builder newBuilder()
Create a Plugin Builder for SendGridAppender- Returns:
- Builder
-
createAppender
public static SendGridAppender createAppender(@PluginConfiguration org.apache.logging.log4j.core.config.Configuration config, @PluginAttribute("name") @Required java.lang.String name, @PluginAttribute("to") java.lang.String to, @PluginAttribute("cc") java.lang.String cc, @PluginAttribute("bcc") java.lang.String bcc, @PluginAttribute("from") java.lang.String from, @PluginAttribute("replyTo") java.lang.String replyTo, @PluginAttribute("subject") java.lang.String subject, @PluginAttribute("host") java.lang.String host, @PluginAttribute(value="apiKey",sensitive=true) java.lang.String apiKey, @PluginAttribute("sandboxMode") java.lang.String sandboxMode, @PluginAttribute("bufferSize") java.lang.String bufferSize, @PluginElement("Layout") org.apache.logging.log4j.core.Layout<? extends java.io.Serializable> layout, @PluginElement("Filter") org.apache.logging.log4j.core.Filter filter, @PluginAttribute("ignoreExceptions") java.lang.String ignore)
Deprecated.UsenewBuilder()to create and configure aSendGridAppender.Builderinstance.Create a SendGrid Appender.- Parameters:
config- The logging Configurationname- The name of the Appenderto- The comma-separated list of recipient email addresses.cc- The comma-separated list of CC email addresses.bcc- The comma-separated list of BCC email addresses.from- The email address of the sender.replyTo- The comma-separated list of reply-to email addresses.subject- The subject of the email message.host- The SendGrid host (defaults to api.sendgrid.com).apiKey- The SendGrid API KeysandboxMode- Enable The SendGrid Sandbox Mode?bufferSize- How many log events should be buffered for inclusion in the message?layout- The layout to use (defaults to HtmlLayout).filter- The Filter or null (defaults to ThresholdFilter, level of ERROR).ignore- If"true"(default) exceptions encountered when appending events are logged; otherwise they are propagated to the caller.- Returns:
- The SendGridAppender
- See Also:
SendGridAppender.Builder
-
isFiltered
public boolean isFiltered(org.apache.logging.log4j.core.LogEvent event)
Capture all events in CyclicBuffer.- Specified by:
isFilteredin interfaceorg.apache.logging.log4j.core.filter.Filterable- Overrides:
isFilteredin classorg.apache.logging.log4j.core.filter.AbstractFilterable- Parameters:
event- The Log event.- Returns:
- true if the event should be filtered.
-
append
public void append(org.apache.logging.log4j.core.LogEvent event)
Perform SendGridAppender specific appending actions, mainly adding the event to a cyclic buffer and checking if the event triggers an e-mail to be sent.- Parameters:
event- The Log event.
-
-