Added: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/jmx/Server.java URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/jmx/Server.java?rev=1469973&view=auto ============================================================================== --- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/jmx/Server.java (added) +++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/jmx/Server.java Fri Apr 19 17:59:11 2013 @@ -0,0 +1,248 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache license, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the license for the specific language governing permissions and + * limitations under the license. + */ +package org.apache.logging.log4j.core.jmx; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.lang.management.ManagementFactory; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.Executor; +import java.util.concurrent.Executors; + +import javax.management.InstanceAlreadyExistsException; +import javax.management.JMException; +import javax.management.MBeanRegistrationException; +import javax.management.MBeanServer; +import javax.management.MalformedObjectNameException; +import javax.management.NotCompliantMBeanException; +import javax.management.ObjectName; + +import org.apache.logging.log4j.core.Appender; +import org.apache.logging.log4j.core.LoggerContext; +import org.apache.logging.log4j.core.config.LoggerConfig; +import org.apache.logging.log4j.core.selector.ContextSelector; +import org.apache.logging.log4j.status.StatusLogger; + +/** + * Creates MBeans to instrument various classes in the log4j class hierarchy. + * <p> + * All instrumentation for Log4J2 classes can be disabled by setting system + * property {@code -Dlog4j2.disable.jmx=true}. + */ +public class Server { + + private static final String PROPERTY_DISABLE_JMX = "log4j2.disable.jmx"; + + /** + * Either returns the specified name as is, or returns a quoted value + * containing the specified name with the special characters (comma, equals, + * colon, quote, asterisk, or question mark) preceded with a backslash. + * + * @param name + * the name to escape so it can be used as a value in an + * {@link ObjectName}. + * @return the escaped name + */ + public static String escape(String name) { + StringBuilder sb = new StringBuilder(name.length() * 2); + boolean needsQuotes = false; + for (int i = 0; i < name.length(); i++) { + char c = name.charAt(i); + switch (c) { + case ',': + case '=': + case ':': + case '\\': + case '*': + case '?': + sb.append('\\'); + needsQuotes = true; + } + sb.append(c); + } + if (needsQuotes) { + sb.insert(0, '\"'); + sb.append('\"'); + } + return sb.toString(); + } + + /** + * Creates MBeans to instrument the specified selector and other classes in + * the log4j class hierarchy and registers the MBeans in the platform MBean + * server so they can be accessed by remote clients. + * + * @param selector + * starting point in the log4j class hierarchy + * @throws JMException + * if a problem occurs during registration + */ + public static void registerMBeans(ContextSelector selector) + throws JMException { + + // avoid creating Platform MBean Server if JMX disabled + if (Boolean.getBoolean(PROPERTY_DISABLE_JMX)) { + StatusLogger.getLogger().debug( + "JMX disabled for log4j2. Not registering MBeans."); + return; + } + MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); + registerMBeans(selector, mbs); + } + + /** + * Creates MBeans to instrument the specified selector and other classes in + * the log4j class hierarchy and registers the MBeans in the specified MBean + * server so they can be accessed by remote clients. + * + * @param selector + * starting point in the log4j class hierarchy + * @param mbs + * the MBean Server to register the instrumented objects in + * @throws JMException + * if a problem occurs during registration + */ + public static void registerMBeans(ContextSelector selector, + final MBeanServer mbs) throws JMException { + + if (Boolean.getBoolean(PROPERTY_DISABLE_JMX)) { + StatusLogger.getLogger().debug( + "JMX disabled for log4j2. Not registering MBeans."); + return; + } + final Executor executor = Executors.newFixedThreadPool(1); + registerStatusLogger(mbs, executor); + registerContextSelector(selector, mbs, executor); + + List<LoggerContext> contexts = selector.getLoggerContexts(); + registerContexts(contexts, mbs, executor); + + for (final LoggerContext context : contexts) { + context.addPropertyChangeListener(new PropertyChangeListener() { + + @Override + public void propertyChange(PropertyChangeEvent evt) { + if (!LoggerContext.PROPERTY_CONFIG.equals(evt + .getPropertyName())) { + return; + } + // first unregister the MBeans that instrument the + // previous instrumented LoggerConfigs and Appenders + unregisterLoggerConfigs(context, mbs); + unregisterAppenders(context, mbs); + + // now provide instrumentation for the newly configured + // LoggerConfigs and Appenders + try { + registerLoggerConfigs(context, mbs, executor); + registerAppenders(context, mbs, executor); + } catch (Exception ex) { + StatusLogger.getLogger().error( + "Could not register mbeans", ex); + } + } + }); + } + } + + private static void registerStatusLogger(MBeanServer mbs, Executor executor) + throws MalformedObjectNameException, + InstanceAlreadyExistsException, MBeanRegistrationException, + NotCompliantMBeanException { + + StatusLoggerAdmin mbean = new StatusLoggerAdmin(executor); + mbs.registerMBean(mbean, mbean.getObjectName()); + } + + private static void registerContextSelector(ContextSelector selector, + MBeanServer mbs, Executor executor) + throws MalformedObjectNameException, + InstanceAlreadyExistsException, MBeanRegistrationException, + NotCompliantMBeanException { + + ContextSelectorAdmin mbean = new ContextSelectorAdmin(selector); + mbs.registerMBean(mbean, mbean.getObjectName()); + } + + private static void registerContexts(List<LoggerContext> contexts, + MBeanServer mbs, Executor executor) + throws MalformedObjectNameException, + InstanceAlreadyExistsException, MBeanRegistrationException, + NotCompliantMBeanException { + + for (LoggerContext ctx : contexts) { + LoggerContextAdmin mbean = new LoggerContextAdmin(ctx, executor); + mbs.registerMBean(mbean, mbean.getObjectName()); + } + } + + private static void unregisterLoggerConfigs(LoggerContext context, + MBeanServer mbs) { + String pattern = LoggerConfigAdminMBean.PATTERN; + String search = String.format(pattern, context.getName(), "*"); + unregisterAllMatching(search, mbs); + } + + private static void unregisterAppenders(LoggerContext context, + MBeanServer mbs) { + String pattern = AppenderAdminMBean.PATTERN; + String search = String.format(pattern, context.getName(), "*"); + unregisterAllMatching(search, mbs); + } + + private static void unregisterAllMatching(String search, MBeanServer mbs) { + try { + ObjectName pattern = new ObjectName(search); + Set<ObjectName> found = mbs.queryNames(pattern, null); + for (ObjectName objectName : found) { + mbs.unregisterMBean(objectName); + } + } catch (Exception ex) { + StatusLogger.getLogger() + .error("Could not unregister " + search, ex); + } + } + + private static void registerLoggerConfigs(LoggerContext ctx, + MBeanServer mbs, Executor executor) + throws MalformedObjectNameException, + InstanceAlreadyExistsException, MBeanRegistrationException, + NotCompliantMBeanException { + + Map<String, LoggerConfig> map = ctx.getConfiguration().getLoggers(); + for (String name : map.keySet()) { + LoggerConfig cfg = map.get(name); + LoggerConfigAdmin mbean = new LoggerConfigAdmin(ctx.getName(), cfg); + mbs.registerMBean(mbean, mbean.getObjectName()); + } + } + + private static void registerAppenders(LoggerContext ctx, MBeanServer mbs, + Executor executor) throws MalformedObjectNameException, + InstanceAlreadyExistsException, MBeanRegistrationException, + NotCompliantMBeanException { + + Map<String, Appender<?>> map = ctx.getConfiguration().getAppenders(); + for (String name : map.keySet()) { + Appender<?> appender = map.get(name); + AppenderAdmin mbean = new AppenderAdmin(ctx.getName(), appender); + mbs.registerMBean(mbean, mbean.getObjectName()); + } + } +}
Added: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/jmx/StatusLoggerAdmin.java URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/jmx/StatusLoggerAdmin.java?rev=1469973&view=auto ============================================================================== --- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/jmx/StatusLoggerAdmin.java (added) +++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/jmx/StatusLoggerAdmin.java Fri Apr 19 17:59:11 2013 @@ -0,0 +1,122 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache license, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the license for the specific language governing permissions and + * limitations under the license. + */ +package org.apache.logging.log4j.core.jmx; + +import java.util.List; +import java.util.concurrent.Executor; +import java.util.concurrent.atomic.AtomicLong; + +import javax.management.MBeanNotificationInfo; +import javax.management.Notification; +import javax.management.NotificationBroadcasterSupport; +import javax.management.ObjectName; + +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.status.StatusData; +import org.apache.logging.log4j.status.StatusListener; +import org.apache.logging.log4j.status.StatusLogger; + +/** + * Implementation of the {@code StatusLoggerAdminMBean} interface. + */ +public class StatusLoggerAdmin extends NotificationBroadcasterSupport implements + StatusListener, StatusLoggerAdminMBean { + + private final AtomicLong sequenceNo = new AtomicLong(); + private final ObjectName objectName; + + /** + * Constructs a new {@code StatusLoggerAdmin} with the {@code Executor} to + * be used for sending {@code Notification}s asynchronously to listeners. + * + * @param executor + */ + public StatusLoggerAdmin(Executor executor) { + super(executor, createNotificationInfo()); + try { + objectName = new ObjectName(NAME); + } catch (Exception e) { + throw new IllegalStateException(e); + } + StatusLogger.getLogger().registerListener(this); + } + + private static MBeanNotificationInfo createNotificationInfo() { + String[] notifTypes = new String[] { NOTIF_TYPE_DATA, + NOTIF_TYPE_MESSAGE }; + String name = Notification.class.getName(); + String description = "StatusLogger has logged an event"; + return new MBeanNotificationInfo(notifTypes, name, description); + } + + @Override + public String[] getStatusDataHistory() { + List<StatusData> data = getStatusData(); + String[] result = new String[data.size()]; + for (int i = 0; i < result.length; i++) { + result[i] = data.get(i).getFormattedStatus(); + } + return result; + } + + @Override + public List<StatusData> getStatusData() { + return StatusLogger.getLogger().getStatusData(); + } + + @Override + public String getLevel() { + return StatusLogger.getLogger().getLevel().name(); + } + + @Override + public void setLevel(String level) { + StatusLogger.getLogger().setLevel(Level.valueOf(level)); + } + + /* + * (non-Javadoc) + * + * @see + * org.apache.logging.log4j.status.StatusListener#log(org.apache.logging + * .log4j.status.StatusData) + */ + @Override + public void log(StatusData data) { + Notification notifMsg = new Notification(NOTIF_TYPE_MESSAGE, + getObjectName(), nextSeqNo(), now(), data.getFormattedStatus()); + sendNotification(notifMsg); + + Notification notifData = new Notification(NOTIF_TYPE_DATA, + getObjectName(), nextSeqNo(), now()); + notifData.setUserData(data); + sendNotification(notifData); + } + + /** @see StatusLoggerAdminMBean#NAME */ + public ObjectName getObjectName() { + return objectName; + } + + private long nextSeqNo() { + return sequenceNo.getAndIncrement(); + } + + private long now() { + return System.currentTimeMillis(); + } +} Added: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/jmx/StatusLoggerAdminMBean.java URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/jmx/StatusLoggerAdminMBean.java?rev=1469973&view=auto ============================================================================== --- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/jmx/StatusLoggerAdminMBean.java (added) +++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/jmx/StatusLoggerAdminMBean.java Fri Apr 19 17:59:11 2013 @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache license, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the license for the specific language governing permissions and + * limitations under the license. + */ +package org.apache.logging.log4j.core.jmx; + +import java.util.List; + +import org.apache.logging.log4j.status.StatusData; + +/** + * The MBean interface for monitoring and managing the {@code StatusLogger}. + */ +public interface StatusLoggerAdminMBean { + /** Object name of this MBean. */ + String NAME = "org.apache.logging.log4j2:type=StatusLogger"; + + /** + * Notifications with this type have a {@code StatusData} userData object + * and a {@code null} message. + */ + String NOTIF_TYPE_DATA = "com.apache.logging.log4j.core.jmx.statuslogger.data"; + + /** + * Notifications with this type have a formatted status data message string + * but no {@code StatusData} in their userData field. + */ + String NOTIF_TYPE_MESSAGE = "com.apache.logging.log4j.core.jmx.statuslogger.message"; + + /** + * Returns a list with the most recent {@code StatusData} objects in the + * status history. The list has up to 200 entries by default but the length + * can be configured with system property {@code "log4j2.status.entries"}. + * <p> + * Note that the returned objects may contain {@code Throwable}s from + * external libraries. + * + * JMX clients calling this method must be prepared to deal with the errors + * that occur if they do not have the class definition for such + * {@code Throwable}s in their classpath. + * + * @return the most recent messages logged by the {@code StatusLogger}. + */ + List<StatusData> getStatusData(); + + /** + * Returns a string array with the most recent messages in the status + * history. The list has up to 200 entries by default but the length can be + * configured with system property {@code "log4j2.status.entries"}. + * + * @return the most recent messages logged by the {@code StatusLogger}. + */ + String[] getStatusDataHistory(); + + /** + * Returns the {@code StatusLogger} level as a String. + * + * @return the {@code StatusLogger} level. + */ + String getLevel(); + + /** + * Sets the {@code StatusLogger} level to the specified value. + * + * @param level the new {@code StatusLogger} level. + * @throws IllegalArgumentException if the specified level is not one of + * "OFF", "FATAL", "ERROR", "WARN", "INFO", "DEBUG", "TRACE", + * "ALL" + */ + void setLevel(String level); + +} Added: logging/log4j/log4j2/trunk/core/src/main/resources/META-INF/services/com.sun.tools.jconsole.JConsolePlugin URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/resources/META-INF/services/com.sun.tools.jconsole.JConsolePlugin?rev=1469973&view=auto ============================================================================== --- logging/log4j/log4j2/trunk/core/src/main/resources/META-INF/services/com.sun.tools.jconsole.JConsolePlugin (added) +++ logging/log4j/log4j2/trunk/core/src/main/resources/META-INF/services/com.sun.tools.jconsole.JConsolePlugin Fri Apr 19 17:59:11 2013 @@ -0,0 +1 @@ +org.apache.logging.log4j.core.jmx.ClientGUIJConsolePlugin Modified: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/async/perftest/IPerfTestRunner.java URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/async/perftest/IPerfTestRunner.java?rev=1469973&r1=1469972&r2=1469973&view=diff ============================================================================== --- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/async/perftest/IPerfTestRunner.java (original) +++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/async/perftest/IPerfTestRunner.java Fri Apr 19 17:59:11 2013 @@ -1,3 +1,19 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache license, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the license for the specific language governing permissions and + * limitations under the license. + */ package org.apache.logging.log4j.core.async.perftest; import com.lmax.disruptor.collections.Histogram; Modified: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/async/perftest/MTPerfTest.java URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/async/perftest/MTPerfTest.java?rev=1469973&r1=1469972&r2=1469973&view=diff ============================================================================== --- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/async/perftest/MTPerfTest.java (original) +++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/async/perftest/MTPerfTest.java Fri Apr 19 17:59:11 2013 @@ -1,3 +1,19 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache license, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the license for the specific language governing permissions and + * limitations under the license. + */ package org.apache.logging.log4j.core.async.perftest; import java.io.File; Modified: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/async/perftest/PerfTest.java URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/async/perftest/PerfTest.java?rev=1469973&r1=1469972&r2=1469973&view=diff ============================================================================== --- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/async/perftest/PerfTest.java (original) +++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/async/perftest/PerfTest.java Fri Apr 19 17:59:11 2013 @@ -1,3 +1,19 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache license, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the license for the specific language governing permissions and + * limitations under the license. + */ package org.apache.logging.log4j.core.async.perftest; import java.io.FileWriter; Modified: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/async/perftest/PerfTestDriver.java URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/async/perftest/PerfTestDriver.java?rev=1469973&r1=1469972&r2=1469973&view=diff ============================================================================== --- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/async/perftest/PerfTestDriver.java (original) +++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/async/perftest/PerfTestDriver.java Fri Apr 19 17:59:11 2013 @@ -1,3 +1,19 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache license, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the license for the specific language governing permissions and + * limitations under the license. + */ package org.apache.logging.log4j.core.async.perftest; import java.io.BufferedReader; Modified: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/async/perftest/PerfTestResultFormatter.java URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/async/perftest/PerfTestResultFormatter.java?rev=1469973&r1=1469972&r2=1469973&view=diff ============================================================================== --- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/async/perftest/PerfTestResultFormatter.java (original) +++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/async/perftest/PerfTestResultFormatter.java Fri Apr 19 17:59:11 2013 @@ -1,3 +1,19 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache license, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the license for the specific language governing permissions and + * limitations under the license. + */ package org.apache.logging.log4j.core.async.perftest; import java.io.BufferedReader; Modified: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/async/perftest/RunLog4j1.java URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/async/perftest/RunLog4j1.java?rev=1469973&r1=1469972&r2=1469973&view=diff ============================================================================== --- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/async/perftest/RunLog4j1.java (original) +++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/async/perftest/RunLog4j1.java Fri Apr 19 17:59:11 2013 @@ -1,3 +1,19 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache license, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the license for the specific language governing permissions and + * limitations under the license. + */ package org.apache.logging.log4j.core.async.perftest; import org.apache.log4j.LogManager; Modified: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/async/perftest/RunLog4j2.java URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/async/perftest/RunLog4j2.java?rev=1469973&r1=1469972&r2=1469973&view=diff ============================================================================== --- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/async/perftest/RunLog4j2.java (original) +++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/async/perftest/RunLog4j2.java Fri Apr 19 17:59:11 2013 @@ -1,3 +1,19 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache license, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the license for the specific language governing permissions and + * limitations under the license. + */ package org.apache.logging.log4j.core.async.perftest; import org.apache.logging.log4j.LogManager; Modified: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/async/perftest/RunLogback.java URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/async/perftest/RunLogback.java?rev=1469973&r1=1469972&r2=1469973&view=diff ============================================================================== --- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/async/perftest/RunLogback.java (original) +++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/async/perftest/RunLogback.java Fri Apr 19 17:59:11 2013 @@ -1,3 +1,19 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache license, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the license for the specific language governing permissions and + * limitations under the license. + */ package org.apache.logging.log4j.core.async.perftest; import org.slf4j.LoggerFactory; Modified: logging/log4j/log4j2/trunk/src/changes/changes.xml URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/changes/changes.xml?rev=1469973&r1=1469972&r2=1469973&view=diff ============================================================================== --- logging/log4j/log4j2/trunk/src/changes/changes.xml (original) +++ logging/log4j/log4j2/trunk/src/changes/changes.xml Fri Apr 19 17:59:11 2013 @@ -23,6 +23,9 @@ <body> <release version="2.0-beta5" date="@TBD@" description="Bug fixes and enhancements"> + <action issue="LOG4J2-207" dev="rgoers" type="add" due-to="Remko Popma"> + Add JMX support. + </action> <action issue="LOG4J2-211" dev="rgoers" type="fix" due-to="Nick Williams"> Removing extra spaces in entry and exit method output. </action> Added: logging/log4j/log4j2/trunk/src/site/resources/images/jmx-jconsole-editconfig.png URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/site/resources/images/jmx-jconsole-editconfig.png?rev=1469973&view=auto ============================================================================== Binary file - no diff available. Propchange: logging/log4j/log4j2/trunk/src/site/resources/images/jmx-jconsole-editconfig.png ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: logging/log4j/log4j2/trunk/src/site/resources/images/jmx-jconsole-mbeans.png URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/site/resources/images/jmx-jconsole-mbeans.png?rev=1469973&view=auto ============================================================================== Binary file - no diff available. Propchange: logging/log4j/log4j2/trunk/src/site/resources/images/jmx-jconsole-mbeans.png ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: logging/log4j/log4j2/trunk/src/site/resources/images/jmx-jconsole-statuslogger.png URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/site/resources/images/jmx-jconsole-statuslogger.png?rev=1469973&view=auto ============================================================================== Binary file - no diff available. Propchange: logging/log4j/log4j2/trunk/src/site/resources/images/jmx-jconsole-statuslogger.png ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: logging/log4j/log4j2/trunk/src/site/resources/images/jmx-standalone-editconfig.png URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/site/resources/images/jmx-standalone-editconfig.png?rev=1469973&view=auto ============================================================================== Binary file - no diff available. Propchange: logging/log4j/log4j2/trunk/src/site/resources/images/jmx-standalone-editconfig.png ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: logging/log4j/log4j2/trunk/src/site/resources/images/jmx-standalone-statuslogger.png URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/site/resources/images/jmx-standalone-statuslogger.png?rev=1469973&view=auto ============================================================================== Binary file - no diff available. Propchange: logging/log4j/log4j2/trunk/src/site/resources/images/jmx-standalone-statuslogger.png ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Modified: logging/log4j/log4j2/trunk/src/site/xdoc/manual/jmx.xml URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/site/xdoc/manual/jmx.xml?rev=1469973&r1=1469972&r2=1469973&view=diff ============================================================================== --- logging/log4j/log4j2/trunk/src/site/xdoc/manual/jmx.xml (original) +++ logging/log4j/log4j2/trunk/src/site/xdoc/manual/jmx.xml Fri Apr 19 17:59:11 2013 @@ -19,14 +19,142 @@ <document> <properties> <title>JMX</title> - <author email="[email protected]">Ralph Goers</author> + <author email="[email protected]">Remko Popma</author> </properties> <body> <section name="JMX"> <p> - JMX support is incomplete at this time. Patches are welcome! + Log4J2 has built-in support for JMX. + The StatusLogger, ContextSelector, and all LoggerContexts, + LoggerConfigs and Appenders are instrumented with MBeans and can + be remotely monitored and controlled. </p> + <p>Also included is a simple client GUI that can be used to + monitor the StatusLogger output, as well as to remotely reconfigure + Log4J with a different configuration file, or to edit the + current configuration directly. + </p> + </section> + <a name="Enabling_JMX" /> + <section name="Enabling JMX"> + <p>JMX support is enabled by default. When Log4J initializes, + the StatusLogger, ContextSelector, and all LoggerContexts, + LoggerConfigs and Appenders are instrumented with MBeans. + To disable JMX completely, and prevent these MBeans from being created, + specify system property <code>log4j2.disable.jmx=true</code> when you start + the Java VM. + </p> + <a name="Local" /> + <subsection name="Local Monitoring and Management"> + <p>To perform local monitoring you don't need to specify any system + properties. The JConsole tool that is included in the Java JDK can be + used to monitor your application. Start JConsole by typing + <code>$JAVA_HOME/bin/jconsole</code> in a command shell. + For more details, see Oracle's documentation on + <a href="http://docs.oracle.com/javase/7/docs/technotes/guides/management/jconsole.html">how to use JConsole</a>.</p> + </subsection> + <a name="Remote" /> + <subsection name="Remote Monitoring and Management"> + <p>To enable monitoring and management from remote systems, set the following system property when starting the Java VM. + </p><p> + <code>com.sun.management.jmxremote.port=portNum</code> + </p><p> + In the property above, <code>portNum</code> is the port number through + which you want to enable JMX RMI connections. + </p><p> + For more details, see Oracle's documentation on + <a href="http://docs.oracle.com/javase/7/docs/technotes/guides/management/agent.html#gdenl">Remote + Monitoring and Management</a>.</p> + </subsection> + </section> + <a name="Log4J_MBeans" /> + <section name="Log4J Instrumented Components"> + <p>The screenshot below shows the Log4J MBeans in JConsole.</p> + <p><img src="../images/jmx-jconsole-mbeans.png" /></p> + </section> + <a name="ClientGUI" /> + <section name="Client GUI"> + <p>Log4J includes a basic client GUI that can be used to + monitor the StatusLogger output and to remotely modify the Log4J + configuration. The client GUI can be run as a stand-alone application + or as a JConsole plug-in.</p> + <subsection name="Running the Client GUI as a JConsole Plug-in"> + <p>To run the Log4J JMX Client GUI as a JConsole Plug-in, + start JConsole with the following command: + </p> + <p><code>$JAVA_HOME/bin/jconsole -pluginpath /path/to/log4j-core-2.0.jar</code></p> + <p>If you execute the above command and connect to your application, + you will see an extra "Log4j2" tab in the JConsole window. + This tab contains the client GUI, with the StatusLogger selected. + The screenshot below shows the StatusLogger panel in JConsole. + </p> + <p><img src="../images/jmx-jconsole-statuslogger.png" /></p> + </subsection> + <subsection name="Remotely Editing the Log4J Configuration"> + <p>The client GUI also contains a simple editor that can be used + to remotely change the Log4J configuration. + </p><p> + The screenshot below shows the configuration edit panel in JConsole. + </p> + <p><img src="../images/jmx-jconsole-editconfig.png" /></p> + <p>The configuration edit panel provides two ways to modify + the Log4J configuration: specifying a different configuration location + URI, or modifying the configuration XML directly in the editor panel.</p> + <p>If you specify a different configuration location URI and + click the "Reconfigure from Location" button, the specified file + or resource must exist and be readable by the application, + or an error will occur and the configuration will not change. + If an error occurred while processing the contents of the specified resource, + Log4J will keep its original configuration, but the editor panel + will show the contents of the file you specified. </p> + <p> + The text area showing the contents of the configuration file is + editable, and you can directly modify the configuration in this + editor panel. Clicking the "Reconfigure with XML below" button will + send the configuration text to the remote application where it + will be used to reconfigure Log4J on the fly. + This will not overwrite any configuration file. + Reconfiguring with text from the editor happens in memory only and + the text is not permanently stored anywhere. + </p> + </subsection> + <a name="ClientStandAlone" /> + <subsection name="Running the Client GUI as a Stand-alone Application"> + <p>To run the Log4J JMX Client GUI as a stand-alone application, + run the following command: + </p> + <p><code>$JAVA_HOME/bin/java -cp /path/to/log4j-core-2.0.jar org.apache.logging.log4j.core.jmx.ClientGUI <options></code></p> + <p>Where <code>options</code> are one of the following:</p> + <ul> + <li><code><host>:<port></code></li> + <li><code>service:jmx:rmi:///jndi/rmi://<host>:<port>/jmxrmi</code></li> + <li><code>service:jmx:rmi://<host>:<port>/jndi/rmi://<host>:<port>/jmxrmi</code></li> + </ul> + <p>The port number must be the same as the portNum specified when + you started the application you want to monitor. + </p> + <p>For example, if you started your application with these options:</p> + <pre>com.sun.management.jmxremote.port=33445 +com.sun.management.jmxremote.authenticate=false +com.sun.management.jmxremote.ssl=false</pre> + <p><b>(Note that this disables <em>all</em> security so this is not recommended + for production environments. + Oracle's documentation on + <a href="http://docs.oracle.com/javase/7/docs/technotes/guides/management/agent.html#gdenl">Remote + Monitoring and Management</a> provides details on how to configure + JMX more securely with password authentication and SSL.)</b></p> + <p>Then you can run the client with this command:</p> + <p><code>$JAVA_HOME/bin/java -cp /path/to/log4j-core-2.0.jar org.apache.logging.log4j.core.jmx.ClientGUI localhost:33445</code></p> + <p>The screenshot below shows the StatusLogger panel of the client + GUI when running as a stand-alone application.</p> + <p><img src="../images/jmx-standalone-statuslogger.png" /></p> + <p>The screenshot below shows the configuration editor panel of the + client GUI when running as a stand-alone application.</p> + <p><img src="../images/jmx-standalone-editconfig.png" /></p> + + </subsection> </section> + </body> </document>
