Bug 38662

Summary: SMTPAppender does not output newlines between stack trace lines
Product: Log4j Reporter: David D. Kilzer <ddkilzer>
Component: AppenderAssignee: log4j-dev <log4j-dev>
Status: RESOLVED FIXED    
Severity: normal Keywords: PatchAvailable
Priority: P2    
Version: 1.2   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Attachments: Patch v1

Description David D. Kilzer 2006-02-15 22:21:41 UTC
Summary:

The SMTPAppender class does not output any newline characters between stack
trace lines when appending the stack trace to the end of a mail message.

Steps to reproduce:

1. Configure log4j.xml to use the SMTPAppender to send a message.
2. Run java code that will generate a log event that will be sent by the
configured SMTPAppender.

Expected results:

The stack trace in the message should have newlines between stack trace lines:

java.net.ConnectException: Connection refused: connect
	at java.net.PlainSocketImpl.socketConnect(Native Method)
	at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
	at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)
	at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)
	at java.net.Socket.connect(Socket.java:452)
	at java.net.Socket.connect(Socket.java:402)
	at java.net.Socket.<init>(Socket.java:309)
	at java.net.Socket.<init>(Socket.java:124)

Actual results:

The stack trace in the message does NOT have newlines between stack trace lines
(looks much worse when viewing in a mail client):

java.net.ConnectException: Connection refused: connect	at
java.net.PlainSocketImpl.socketConnect(Native Method)	at
java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)	at
java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)	at
java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)	at
java.net.Socket.connect(Socket.java:452)	at
java.net.Socket.connect(Socket.java:402)	at
java.net.Socket.<init>(Socket.java:309)	at java.net.Socket.<init>(Socket.java:124)

Regression:

Tested on log4j-1.2.8 and log4j-1.2.13.  Both of them exhibit the "actual
behavior" documented above.
Comment 1 David D. Kilzer 2006-02-15 22:25:12 UTC
Created attachment 17705 [details]
Patch v1

Patch v1 fixes the issue for me when log4j is built locally.

Note that the email client I'm using happens to be MS Outlook XP (which makes
interesting choices for where to put line breaks), but I still think the stack
trace should have newlines after each line.
Comment 2 Curt Arnold 2006-08-31 19:57:54 UTC
Not sure that it really should be Layout.LINE_SEP or '\n', but log4j 1.3 already had the problem fixed using 
LINE_SEP so stuck with that.  Committed in log4j 1.2 branch in rev 439036.