logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Thies Wellpott (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (LOG4J2-1192) Dynamic Subject for SMTP Appender
Date Thu, 03 Dec 2015 16:17:11 GMT

    [ https://issues.apache.org/jira/browse/LOG4J2-1192?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15038013#comment-15038013
] 

Thies Wellpott commented on LOG4J2-1192:
----------------------------------------

Hi!

I created a new Appender (ExtendedSmtpAppender) which optionally allows to use PatternLayout
for the subject.

Additionally, it supports burst summarizing, so you will not get 1000 error emails wihtin
a few seconds or minutes. Use case: Send all ERROR-logs via Email to support/developer. On
a broken network or database this can cause hundreds of the same error email.
This appender does the following:
- the first occurrence is email immediatly
- all following similar ERROR logs are buffered for a certain time (similarity and time is
configurable)
- after the time passed, a summary email with summary info (number of events, time) and the
first and last event is send

See two attached source codes (the may be moved into the org.apache.logging.log4j.core package
and included into the log4j2 project).

Example configuration (inside <Appenders>):
		<SMTPx name="ErrorMail" smtpHost="mailer02.xxxx.de" smtpPort="25"
				from="your name &lt;noReply@xxx.de>"  to="${errorEmailAddresses}"
				subject="[PROJECT-ID, ${hostName}, ${web:contextPath}] %p: %c{1} - %m%notEmpty{ =>%ex{short})}"
				subjectWithLayout="true"  bufferSize="5"
				burstSummarizingSeconds="300" bsCountInSubject="S" bsMessageMaskDigits="true"
				bsExceptionOrigin="true" >
			<PatternLayout pattern="-- %d  %p  %c [%.20t,%x]  %m%n" charset="UTF-8" />		<!--
SMTP uses fixed charset for message -->
		</SMTPx>
		<Async name="AsyncErrorMail" blocking="false" errorRef="Console">
			<AppenderRef ref="ErrorMail"/>
		</Async>


> Dynamic Subject for SMTP Appender
> ---------------------------------
>
>                 Key: LOG4J2-1192
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1192
>             Project: Log4j 2
>          Issue Type: New Feature
>          Components: Appenders
>    Affects Versions: 2.4.1
>         Environment: ALL
>            Reporter: Jörg Bretschneider
>              Labels: features
>
> It is annoying to have log messages sent to users via SMTP Appender with a static subject,
requiring recipients to open each of possibly a vast amount of log emails in order to find
out what went wrong.
> Users should be able to insert runtime diagnostic context information to the message
text AND to the message subject as well. 
> While the first seems to be working with Patternlayout using the mechanism with the %X{<key>}
pattern based on a NDC or MDC <key> in the "ConversionPattern" parameter, it does NOT
work with the "Subject" parameter with log4j (neither 1.2 nor 2.x), though some bloggers suggest
it, e.g. http://stackoverflow.com/a/7015453. 
> See http://stackoverflow.com/questions/29435825/log4j2-custom-email-subject-from-map
as an example where others found this also.
> This issue should have been fixed long ago.
> I suggest to extend SMTP appender in order to be able to use %X and other Pattern conversion
in the "Subject" parameter properly. 
> http://openutils.sourceforge.net/openutils-log4j/smtpappender.html 
> has already done the part for applying PatternLayout to the SMTP Appender "Subject".
I didn't test if this works properly. 
> Maybe this work can be included into log4j with minimal effort?
> This feature has originally been realized in LOGBACK using an MDC in Patternlayouts:
http://logback.qos.ch/manual/mdc.html



--
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


Mime
View raw message