Class SmtpAppender

  • All Implemented Interfaces:
    Appender, Filterable, LocationAware, LifeCycle, LifeCycle2

    @Plugin(name="SMTP",
            category="Core",
            elementType="appender",
            printObject=true)
    public final class SmtpAppender
    extends AbstractAppender
    Send 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 SmtpAppender keeps only the last BufferSize logging 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 formatted 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.

    • Constructor Detail

      • SmtpAppender

        private SmtpAppender​(java.lang.String name,
                             Filter filter,
                             Layout<? extends java.io.Serializable> layout,
                             SmtpManager manager,
                             boolean ignoreExceptions,
                             Property[] properties)
    • Method Detail

      • createAppender

        @PluginFactory
        public static SmtpAppender createAppender​(@PluginConfiguration
                                                  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("smtpProtocol")
                                                  java.lang.String smtpProtocol,
                                                  @PluginAttribute("smtpHost")
                                                  java.lang.String smtpHost,
                                                  @PluginAttribute(value="smtpPort",defaultString="0") @ValidPort
                                                  java.lang.String smtpPortStr,
                                                  @PluginAttribute("smtpUsername")
                                                  java.lang.String smtpUsername,
                                                  @PluginAttribute(value="smtpPassword",sensitive=true)
                                                  java.lang.String smtpPassword,
                                                  @PluginAttribute("smtpDebug")
                                                  java.lang.String smtpDebug,
                                                  @PluginAttribute("bufferSize")
                                                  java.lang.String bufferSizeStr,
                                                  @PluginElement("Layout")
                                                  Layout<? extends java.io.Serializable> layout,
                                                  @PluginElement("Filter")
                                                  Filter filter,
                                                  @PluginAttribute("ignoreExceptions")
                                                  java.lang.String ignore)
        Create a SmtpAppender.
        Parameters:
        name - The name of the Appender.
        to - 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.
        smtpProtocol - The SMTP transport protocol (such as "smtps", defaults to "smtp").
        smtpHost - The SMTP hostname to send to.
        smtpPortStr - The SMTP port to send to.
        smtpUsername - The username required to authenticate against the SMTP server.
        smtpPassword - The password required to authenticate against the SMTP server.
        smtpDebug - Enable mail session debuging on STDOUT.
        bufferSizeStr - 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 SmtpAppender.
      • isFiltered

        public boolean isFiltered​(LogEvent event)
        Capture all events in CyclicBuffer.
        Specified by:
        isFiltered in interface Filterable
        Overrides:
        isFiltered in class AbstractFilterable
        Parameters:
        event - The Log event.
        Returns:
        true if the event should be filtered.
      • append

        public void append​(LogEvent event)
        Perform SmtpAppender 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.