Thanks for your message. There are many improvements that can be applied to log4j's JMX support. I intend to bring many improvements in the near future.
You might want to apply the following patch that corrects a problem with log4j's current implementation of JMX support.
http://marc.theaimsgroup.com/?l=log4j-dev&m=105412197117040&w=2
I have not tried it but it makes sense.
At 11:05 AM 7/21/2003 -0400, you wrote:
Hi,
I just went through a few bumps trying to get Log4J's JMX support (in 1.2.8) working nicely with WebLogic 6.1 (SP 3) and thought I'd share the results, since info on getting JMX set up seems pretty slim everywhere you look (WebLogic docs, Sun JMX docs, Log4J javadoc).
The main problem is registering the Log4J MBeans with WebLogic's MBean server. First, there needs to be a place to put the registration code. I created a WebLogic startup class (T3StartupDef subclass) to have the registration code run at startup time, and included the class in a jar file on WebLogic's system classpath.
The startup class needs to get WebLogic's MBean server. The WebLogic docs about registering custom MBeans are very sketchy, and I ended up piecing together the answer myself. WebLogic publishes these objects called MBean homes in JNDI. There are different MBean homes with different sets of MBeans in them - you want the local MBean home. This amounts to:
1. Getting the JNDI InitialContext 2. Looking up weblogic.management.home.localhome (best to use the MBeanHome.LOCAL_JNDI_NAME string constant for the current name) 3. Cast the result to MBeanHome 4. Call getMBeanServer to get your MBean server
>From there it's just standard JMX, and you just have to worry about which Log4J MBeans to register. Like the org.apache.log4j.xml.Agent class, I created a HierarchyDynamicMBean and registered that with the server. Since the Hierarchy MBean only creates an MBean for the root Logger, I also got the list of all Loggers from LogManager.getLoggerRepository().getCurrentLoggers() and created MBeans for those too. Because Hierarchy's addLoggerMBean operation does some extra things, I used it instead of just creating new MBean objects. But addLoggerMBean is package-private, so I had to call it through the MBean invoke method, which is a little awkward. Anyway, that gets you MBeans for the default Hierarchy, all the Loggers that are there in the configuration, all the Appenders off those Loggers, and all the Layouts for those Appenders.
As for the client, I was able to get the MBeans back from a remote server with a few lines of Java code (actually BeanShell script here): import javax.management.*; import weblogic.management.*; home = Helper.getMBeanHome("system", "passwd", "t3://localhost:7001", "myserver"); server = home.getMBeanServer(); print(server.getAttribute(new ObjectName("log4j:logger=root"), "priority"));
I also used MC4J to view the MBeans and fiddle around with them so I would understand what they could do. You can get MC4J from http://mc4j.sourceforge.net/ and it's very simple to set up with WebLogic. You launch MC4J, try to access a WebLogic server on your local machine, it prompts you for your WebLogic install and your system username and password, and you're connected to your WebLogic. All the Log4J MBeans are listed together under the "log4j" domain.
Pretty easy. So far it looks like I can at least change the priority of existing Loggers, which is what the org.apache.log4j.servlet.ConfigurationServlet in jakarta-log4j-sandbox does currently as well. One thing that's definitely not there, is the ability to reset or load a new configuration into the Hierarchy. Looks like there's potential to do a lot with the Appenders, though - I just haven't figured out exactly what I need to do there.
Note that I avoided using org.apache.log4j.xml.Agent, the Sun RI MBean server, and the HTML adapter. This is because I wanted the MBeans to appear alongside my WebLogic MBeans so I could manage them together. Though registration was a little difficult to figure out, it turned out to be pretty minimal code.
Hope this helps others, Jim Doyle
--
Ceki For log4j documentation consider "The complete log4j manual"
ISBN: 2970036908 http://www.qos.ch/shop/products/clm_t.jsp
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
