<font size=2 face="sans-serif">Hi Folks.<br><br>I have searched the archives for information on how to register Logback
to the JMX server in WebSphere and did not find any information.<br>I did some research and found that IBM has two MBean servers. I posted
information to the users mailing list on how to get WebSphere to use the
platform server.<br><br>I have also done some research and development on how to get Logback to
register to the JSR160RMI connector.<br><br>I modified the JMXConfiguratorAction class to look for a system property
called ch.qos.logback.WebSphere to be set to true.<br>If the property is set to true, it will register the MBean to the MBean
server at the JSR160RMI connector instead of the platform MBean server.<br><br>I have tested this at the level of a proof of concept. I would really like
to see this feature be added to the code for Logback.<br>I have included the source code as part of this post. <br><br>Please feel free to contact me at dale.chapman@medavie.bluecross.ca if
you have any questions or comments about this.<br><br>Thanks!<br><br><br><br>packagech.qos.logback.classic.joran.action;<br><br>importjava.lang.management.ManagementFactory;<br><br>importjavax.management.MBeanServer;<br>importjavax.management.ObjectName;<br><br>importorg.xml.sax.Attributes;<br><br>importcom.ibm.websphere.management.AdminServiceFactory;<br>importcom.ibm.websphere.management.MBeanFactory;<br>importcom.ibm.websphere.management.RuntimeCollaborator;<br>importcom.ibm.websphere.management.UserMBeanCollaborator;<br>importcom.ibm.websphere.management.exception.AdminException;<br><br>importch.qos.logback.classic.LoggerContext;<br>importch.qos.logback.classic.jmx.JMXConfigurator;<br>importch.qos.logback.classic.jmx.MBeanUtil;<br>importch.qos.logback.core.joran.action.Action;<br>importch.qos.logback.core.joran.spi.ActionException;<br>importch.qos.logback.core.joran.spi.InterpretationContext;<br>importch.qos.logback.core.util.OptionHelper;<br><br>publicclassJMXConfiguratorAction extendsAction {<br><br> staticfinalString OBJECT_NAME_ATTRIBUTE_NAME= "objectName";<br> staticfinalString CONTEXT_NAME_ATTRIBUTE_NAME= "contextName";<br> staticfinalcharJMX_NAME_SEPARATOR= ',';<br> <br> @Override<br> publicvoidbegin(InterpretationContext ec, String name, Attributes attributes)<br> throwsActionException {<br> addInfo("begin");<br><br><br> String contextName = context.getName();<br> String contextNameAttributeVal = attributes<br> .getValue(CONTEXT_NAME_ATTRIBUTE_NAME);<br> if(!OptionHelper.isEmpty(contextNameAttributeVal)) {<br> contextName = contextNameAttributeVal;<br> }<br><br> String objectNameAsStr;<br> String objectNameAttributeVal = attributes<br> .getValue(OBJECT_NAME_ATTRIBUTE_NAME);<br> if(OptionHelper.isEmpty(objectNameAttributeVal)) {<br> objectNameAsStr = MBeanUtil.getObjectNameFor(contextName,<br> JMXConfigurator.class);<br> } else{<br> objectNameAsStr = objectNameAttributeVal;<br> }<br><br> ObjectName objectName = MBeanUtil.string2ObjectName(context, this,<br> objectNameAsStr);<br> if(objectName == null) {<br> addError("Failed construct ObjectName for ["+objectNameAsStr+"]");<br> return;<br> }<br> <br> String websphereFlag = System.getProperty("ch.qos.logback.WebSphere");<br> <br> if(websphereFlag == null|| !websphereFlag.equalsIgnoreCase("true")){<br> <br> MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();<br> if(!MBeanUtil.isRegistered(mbs, objectName))
{<br> // register only of the named
JMXConfigurator has not been previously<br> // registered. Unregistering
an MBean within invocation of itself<br> // caused jconsole to throw
an NPE. (This occurs when the reload* method<br> // unregisters the <br> JMXConfigurator jmxConfigurator
= newJMXConfigurator((LoggerContext) context, mbs,<br> objectName);<br> try{ <br> mbs.registerMBean(jmxConfigurator,
objectName);<br> } catch(Exception e) {<br> addError("Failed
to create mbean", e);<br> }<br> }<br> } else{<br> try{<br>
MBeanFactory mbfactory = AdminServiceFactory.getMBeanFactory();<br>
MBeanServer mbs = mbfactory.getMBeanServer();<br>
RuntimeCollaborator logbackCollaborator = newUserMBeanCollaborator(newJMXConfigurator((LoggerContext)
context, mbs, objectName ));<br>
mbfactory.activateMBean("LogbackMBean", logbackCollaborator,
"logbackMBeanId", "LogbackMBean.xml");<br>
System.out.println("LOGBACK registration with IBM MBeanServer
complete");<br> } catch(AdminException
e) {<br>
System.out.println("LOGBACK registration with IBM MBeanServer
failed");<br>
e.printStackTrace();<br> }<br> }<br> }<br><br> @Override<br> publicvoidend(InterpretationContext ec, String name) throwsActionException
{<br><br> }<br><br>}<br></font><br><font size=2 face="sans-serif"><br>Dale Chapman,<br>Architect - MAAX Support<br>Medavie<br>506-867-4430<br>dale.chapman@medavie.bluecross.ca</font><BR>
-----------------------------------------------------------------------<BR>
<BR>
This communication, including any attached documentation, is intended only for the person or entity to which it is addressed, and may contain confidential, personal, and/or privileged information. Any unauthorized disclosure, copying, or taking action on the contents is strictly prohibited. If you have received this message in error, please contact us immediately so we may correct our records. Please then delete or destroy the original transmission and any subsequent reply. Thank you.<BR>
<BR>
<BR>
<BR>
La présente communication, y compris toute pièce qui y a été jointe, est destinée uniquement à la personne ou à l’entité à laquelle elle a été adressée, et contient des renseignements à caractère confidentiel et personnel. Toute diffusion ou reproduction non autorisée ou toute intervention entreprise relativement à son contenu est strictement interdite. Si vous avez reçu ce message par erreur, veuillez nous le signaler immédiatement afin que nous puissions effectuer la correction à nos dossiers. Veuillez par la suite supprimer ou détruire le contenu de la transmission originale ainsi que toute réponse ultérieure. Merci.<BR>
<BR>
-----------------------------------------------------------------------<BR>