Skip to content

Instantly share code, notes, and snippets.

@danveloper
Created March 20, 2013 21:14
Show Gist options
  • Save danveloper/5208508 to your computer and use it in GitHub Desktop.
Save danveloper/5208508 to your computer and use it in GitHub Desktop.
EnhancedJMSAppender -- Real Time Logging Project
public class EnhancedJMSAppender extends JMSAppender {
private String appName;
/**
* Method enriches the headers so that JMS consumers know who you are
*/
@Override
public void append(LoggingEvent event) {
if(!checkEntryConditions()) {
return;
}
try {
ActiveMQConnection activeMqConnection = (ActiveMQConnection)getTopicConnection();
if (!activeMqConnection.isStarted()) {
activeMqConnection.start();
}
ObjectMessage msg = getTopicSession().createObjectMessage();
if (getLocationInfo()) {
event.getLocationInformation();
}
msg.setStringProperty("application.name", appName);
msg.setStringProperty("hostname", InetAddress.getLocalHost().getHostName());
msg.setStringProperty("ip-address", InetAddress.getLocalHost().getHostAddress());
msg.setObject(event);
getTopicPublisher().publish(msg);
} catch(JMSException e) {
errorHandler.error("Could not publish message in JMSAppender ["+name+"].", e,
ErrorCode.GENERIC_FAILURE);
} catch(RuntimeException e) {
errorHandler.error("Could not publish message in JMSAppender ["+name+"].", e,
ErrorCode.GENERIC_FAILURE);
} catch (UnknownHostException e) {
errorHandler.error("Could not publish message in JMSAppender ["+name+"].", e,
ErrorCode.GENERIC_FAILURE);
}
}
public void setAppName(String appName) {
this.appName = appName;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment