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 "Remko Popma (JIRA)" <ji...@apache.org> on 2014/01/07 05:43:51 UTC

[jira] [Updated] (LOG4J2-488) SMTPAppender Does Not Log Below Level "Error"

     [ https://issues.apache.org/jira/browse/LOG4J2-488?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Remko Popma updated LOG4J2-488:
-------------------------------

    Description: 
SMTPAppender attempts to connect to SMTP server only when logging at level Error or Fatal, regardless of the level defined in Log4J2.xml.

This bug sounds similar to LOG4J2-310, "SMTPAppender does not send mails with error or fatal level without prior info event," but it is different.

Steps to reproduce:

This code:
{code}
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

class LogTest {
	private static Logger logger = LogManager.getLogger("LogTest");

	public void testlogger() {
		logger.info("test info"); // does not log
		logger.error("test error"); // logs!
	}

	public static void main(String[] args) {
		LogTest app = new LogTest();
		app.testlogger();
	}
}
{code}

With this configuration file:
{code}
<?xml version="1.0" encoding="UTF-8"?>
<configuration status="warn">
	<!-- Mail server configuration. You don't need to change these to see the 
		problem with SMTPAppender. Because smtpDebug is set to "true" you'll see 
		that the appender makes no attempt whatsoever to connect to an SMTP server 
		while logging at any level other than fatal or error, thus demonstrating 
		the bug. -->
	<properties>
		<property name="receipients">me@example.com</property>
		<property name="from">me@example.com</property>
		<property name="smtpHost">smtp.example.com</property>
		<property name="smtpPort">25</property>
		<property name="smtpProtocol">smtp</property>
		<property name="smtpUser">me</property>
		<property name="smtpPassword">secret</property>
	</properties>
	<appenders>
		<!-- appender to write all info events to stdout -->
		<Console name="Console" target="SYSTEM_OUT">
			<ThresholdFilter level="info" onMatch="NEUTRAL"
				onMismatch="DENY" />
		</Console>
		<!-- appender to send mails (default: error and fatal events) -->
		<SMTP name="Mailer" ignoreExceptions="false" subject="Error log"
			to="${receipients}" from="${from}" smtpHost="${smtpHost}" smtpPort="${smtpPort}"
			smtpProtocol="${smtpProtocol}" smtpUsername="${smtpUser}"
			smtpPassword="${smtpPassword}" smtpDebug="true" bufferSize="2">
		</SMTP>
		<!-- appender to send mails asynchronously -->
		<Async name="AsyncMailer">
			<appender-ref ref="Mailer" />
		</Async>
	</appenders>
	<loggers>
		<!-- logger to send mail on (at least) info level events -->
		<logger name="LogTest" level="info" additivity="true">
			<appender-ref ref="AsyncMailer" />
		</logger>
		<!-- root logger to see what happens (info level and "above") -->
		<root level="info">
			<appender-ref ref="Console" />
		</root>
	</loggers>
</configuration>
{code}

Demonstrates the problem.



  was:
SMTPAppender attempts to connect to SMTP server only when logging at level Error or Fatal, regardless of the level defined in Log4J2.xml.

This bug sounds similar to LOG4J2-310, "SMTPAppender does not send mails with error or fatal level without prior info event," but it is different.

Steps to reproduce:

This code:

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

class LogTest {
	private static Logger logger = LogManager.getLogger("LogTest");

	public void testlogger() {
		logger.info("test info"); // does not log
		logger.error("test error"); // logs!
	}

	public static void main(String[] args) {
		LogTest app = new LogTest();
		app.testlogger();
	}
}

With this configuration file:

<?xml version="1.0" encoding="UTF-8"?>
<configuration status="warn">

	<!-- Mail server configuration. You don't need to change these to see the 
		problem with SMTPAppender. Because smtpDebug is set to "true" you'll see 
		that the appender makes no attempt whatsoever to connect to an SMTP server 
		while logging at any level other than fatal or error, thus demonstrating 
		the bug. -->
	<properties>
		<property name="receipients">me@example.com</property>
		<property name="from">me@example.com</property>
		<property name="smtpHost">smtp.example.com</property>
		<property name="smtpPort">25</property>
		<property name="smtpProtocol">smtp</property>
		<property name="smtpUser">me</property>
		<property name="smtpPassword">secret</property>
	</properties>

	<appenders>

		<!-- appender to write all info events to stdout -->
		<Console name="Console" target="SYSTEM_OUT">
			<ThresholdFilter level="info" onMatch="NEUTRAL"
				onMismatch="DENY" />
		</Console>

		<!-- appender to send mails (default: error and fatal events) -->
		<SMTP name="Mailer" ignoreExceptions="false" subject="Error log"
			to="${receipients}" from="${from}" smtpHost="${smtpHost}" smtpPort="${smtpPort}"
			smtpProtocol="${smtpProtocol}" smtpUsername="${smtpUser}"
			smtpPassword="${smtpPassword}" smtpDebug="true" bufferSize="2">
		</SMTP>
		<!-- appender to send mails asynchronously -->
		<Async name="AsyncMailer">
			<appender-ref ref="Mailer" />
		</Async>

	</appenders>
	<loggers>

		<!-- logger to send mail on (at least) info level events -->
		<logger name="LogTest" level="info" additivity="true">
			<appender-ref ref="AsyncMailer" />
		</logger>

		<!-- root logger to see what happens (info level and "above") -->
		<root level="info">
			<appender-ref ref="Console" />
		</root>

	</loggers>
</configuration>

Demonstrates the problem.




> SMTPAppender Does Not Log Below Level "Error"
> ---------------------------------------------
>
>                 Key: LOG4J2-488
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-488
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Appenders
>    Affects Versions: 2.0-beta9
>         Environment: Tomcat, Servlet 3.0
>            Reporter: Michael Mast
>            Priority: Minor
>
> SMTPAppender attempts to connect to SMTP server only when logging at level Error or Fatal, regardless of the level defined in Log4J2.xml.
> This bug sounds similar to LOG4J2-310, "SMTPAppender does not send mails with error or fatal level without prior info event," but it is different.
> Steps to reproduce:
> This code:
> {code}
> import org.apache.logging.log4j.LogManager;
> import org.apache.logging.log4j.Logger;
> class LogTest {
> 	private static Logger logger = LogManager.getLogger("LogTest");
> 	public void testlogger() {
> 		logger.info("test info"); // does not log
> 		logger.error("test error"); // logs!
> 	}
> 	public static void main(String[] args) {
> 		LogTest app = new LogTest();
> 		app.testlogger();
> 	}
> }
> {code}
> With this configuration file:
> {code}
> <?xml version="1.0" encoding="UTF-8"?>
> <configuration status="warn">
> 	<!-- Mail server configuration. You don't need to change these to see the 
> 		problem with SMTPAppender. Because smtpDebug is set to "true" you'll see 
> 		that the appender makes no attempt whatsoever to connect to an SMTP server 
> 		while logging at any level other than fatal or error, thus demonstrating 
> 		the bug. -->
> 	<properties>
> 		<property name="receipients">me@example.com</property>
> 		<property name="from">me@example.com</property>
> 		<property name="smtpHost">smtp.example.com</property>
> 		<property name="smtpPort">25</property>
> 		<property name="smtpProtocol">smtp</property>
> 		<property name="smtpUser">me</property>
> 		<property name="smtpPassword">secret</property>
> 	</properties>
> 	<appenders>
> 		<!-- appender to write all info events to stdout -->
> 		<Console name="Console" target="SYSTEM_OUT">
> 			<ThresholdFilter level="info" onMatch="NEUTRAL"
> 				onMismatch="DENY" />
> 		</Console>
> 		<!-- appender to send mails (default: error and fatal events) -->
> 		<SMTP name="Mailer" ignoreExceptions="false" subject="Error log"
> 			to="${receipients}" from="${from}" smtpHost="${smtpHost}" smtpPort="${smtpPort}"
> 			smtpProtocol="${smtpProtocol}" smtpUsername="${smtpUser}"
> 			smtpPassword="${smtpPassword}" smtpDebug="true" bufferSize="2">
> 		</SMTP>
> 		<!-- appender to send mails asynchronously -->
> 		<Async name="AsyncMailer">
> 			<appender-ref ref="Mailer" />
> 		</Async>
> 	</appenders>
> 	<loggers>
> 		<!-- logger to send mail on (at least) info level events -->
> 		<logger name="LogTest" level="info" additivity="true">
> 			<appender-ref ref="AsyncMailer" />
> 		</logger>
> 		<!-- root logger to see what happens (info level and "above") -->
> 		<root level="info">
> 			<appender-ref ref="Console" />
> 		</root>
> 	</loggers>
> </configuration>
> {code}
> Demonstrates the problem.



--
This message was sent by Atlassian JIRA
(v6.1.5#6160)

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org