You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Jin Zhao <JZ...@Qcorps.com> on 2001/10/22 19:03:11 UTC
Re: JMS with layout
>>Hello Everybody,
>> Isn't it possible to have JMSAppender with PatternLayout?? ...
>>I am using Message-Driven bean for getting the JMS messages instead of
JMSSink. But i find that it gives me only the message not the formatted
message(according to >>conversion pattern), i was in impression that Layout
can be used with JMS.
>>Any workaround ??
>> Thanks
>> Naresh
You should get a LoggingEvent object from the JMSAppender. You can get all
serialized fields from it, including NDC, priority, thread name etc,
according to you layout pattern. If you are really expecting a layout
formatted string, you need to overwrite the JMSAppender#appender(Event).
Something like the following code block:
================================================================
public
void append(LoggingEvent event) {
if(!checkEntryConditions()) {
return;
}
try {
// Here you format the event before embed it into a JMS Message object
// You can also use a TextMessage instead of ObjectMessage
// TextMessage msg = topicSeesion.createTextMessage();
// msg.setText(this.layout.format(event));
ObjectMessage msg = topicSession.createObjectMessage();
msg.setObject(this.layout.format(event));
topicPublisher.publish(msg);
} catch(Exception e) {
errorHandler.error("Could not publish message in JMSAppender
["+name+"].", e,
ErrorCode.GENERIC_FAILURE);
}
}
================================================================
On the receiver side, you can extract the layout formatted string using the
following block
=================================================================
String loggings = (String)((ObjectMessage)message).getObject());
// or String loggings = ((TextMessage)message).getText());
=================================================================
If you tried it, please tell us the result.
Thanx,
Jin
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org