Created
March 20, 2013 21:14
-
-
Save danveloper/5208508 to your computer and use it in GitHub Desktop.
EnhancedJMSAppender -- Real Time Logging Project
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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