On Apr 30, 2008, at 10:58 AM, Britton, David wrote:

Robert Pepersack wrote:
Note that the second line isn't prefixed with the text
created by my subclass of PatternLayout.

How can I get all the output to be prefixed with the layout
that I specify?  For example:

2008-04-30 08:59:01 [MyThread] DEBUG MyClass.myMethod(): 220
Connected to server. 2008-04-30 08:59:01 [MyThread] DEBUG
MyClass.myMethod(): 220 Connection will close if idle for more than 5
minutes.


Hi Robert --

You would need to split the line on the line separator, and call a log method for each line.


If you write your message like that, a casual reader of the log would assume that there were multiple log calls. I think it would be cleaner, just to indent the second and subsequent lines so that you get:

2008-04-30 08:59:01 [MyThread] DEBUG MyClass.myMethod(): 220 Connected to server. 220 Connection will close if idle for more than 5 minutes.


To get that, have your custom layout (which I'm guessing either extends or encapsulates PatternLayout) call PatternLayout.format() to get the full output. Then subtract the length of the event.getRenderedMessage() from the length of the formatted message to get the length of the prolog. Then split along line boundaries prepending the appropriate number of blanks.




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to