summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Gemmell <robbie@apache.org>2009-08-16 20:36:33 +0000
committerRobert Gemmell <robbie@apache.org>2009-08-16 20:36:33 +0000
commit8a11b9f6df8882fb704955afcdfec3c1e14fd9bd (patch)
tree0f0ac65e50b0ccbb282652e1fbdaad47d111b7c4
parentb964a52247b0405f2f6da647bff3ac74ad2ab6c6 (diff)
downloadqpid-python-8a11b9f6df8882fb704955afcdfec3c1e14fd9bd.tar.gz
QPID-2052: Enable setting Loggers to inherit their Level from an ancestor. Highlight the Runtime Loggers that have a level defined in the configuration file to aid inheritance visibility.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@804768 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/logging/management/LoggingManagementMBean.java29
-rw-r--r--qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/logging/ConfigurationFileTabControl.java10
-rw-r--r--qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/logging/RuntimeTabControl.java88
3 files changed, 118 insertions, 9 deletions
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/management/LoggingManagementMBean.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/management/LoggingManagementMBean.java
index 1ab9d913c8..ce7d08c8dc 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/management/LoggingManagementMBean.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/management/LoggingManagementMBean.java
@@ -76,10 +76,12 @@ public class LoggingManagementMBean extends AMQManagedObject implements LoggingM
private static final Logger _logger = Logger.getLogger(LoggingManagementMBean.class);
private String _log4jConfigFileName;
private int _log4jLogWatchInterval;
+ private static final String INHERITED = "INHERITED";
private static final String[] LEVELS = new String[]{Level.ALL.toString(), Level.TRACE.toString(),
Level.DEBUG.toString(), Level.INFO.toString(),
Level.WARN.toString(), Level.ERROR.toString(),
- Level.FATAL.toString(),Level.OFF.toString()};
+ Level.FATAL.toString(),Level.OFF.toString(),
+ INHERITED};
static TabularType _loggerLevelTabularType;
static CompositeType _loggerLevelCompositeType;
@@ -225,6 +227,13 @@ public class LoggingManagementMBean extends AMQManagedObject implements LoggingM
{
return false;
}
+
+ if(newLevel == null)
+ {
+ //A null Level reference implies inheritance. Setting the runtime RootLogger
+ //to null is catastrophic (and prevented by Log4J at startup and runtime anyway).
+ return false;
+ }
_logger.info("Setting RootLogger level to " + level);
@@ -237,6 +246,13 @@ public class LoggingManagementMBean extends AMQManagedObject implements LoggingM
//method to convert from a string to a log4j Level, throws exception if the given value is invalid
private Level getLevel(String level) throws Exception
{
+ if("null".equalsIgnoreCase(level) || INHERITED.equalsIgnoreCase(level))
+ {
+ //the string "null" or "inherited" signals to inherit from a parent logger,
+ //using a null Level reference for the logger.
+ return null;
+ }
+
Level newLevel = Level.toLevel(level);
//above Level.toLevel call returns a DEBUG Level if the request fails. Check the result.
@@ -611,7 +627,7 @@ public class LoggingManagementMBean extends AMQManagedObject implements LoggingM
}
//update the element with the new level/priority
- levelElement.setAttribute("value", level);
+ levelElement.setAttribute("value", level.toLowerCase());
//output the new file
return writeUpdatedConfigFile(_log4jConfigFileName, doc);
@@ -699,7 +715,14 @@ public class LoggingManagementMBean extends AMQManagedObject implements LoggingM
//check that the specified level is a valid log4j Level
try
{
- getLevel(level);
+ Level newLevel = getLevel(level);
+ if(newLevel == null)
+ {
+ //A null Level reference implies inheritance. Setting the config file RootLogger
+ //to "null" or "inherited" just ensures it defaults to DEBUG at startup as Log4J
+ //prevents this catastrophic situation at startup and runtime anyway.
+ return false;
+ }
}
catch (Exception e)
{
diff --git a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/logging/ConfigurationFileTabControl.java b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/logging/ConfigurationFileTabControl.java
index e2c3c2a075..5496b4548c 100644
--- a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/logging/ConfigurationFileTabControl.java
+++ b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/logging/ConfigurationFileTabControl.java
@@ -194,11 +194,15 @@ public class ConfigurationFileTabControl extends TabControl
}
Label noteLabel = _toolkit.createLabel(_headerComposite,
- "NOTE: These options modify the config file. " +
- "Changes take effect if LogWatch is enabled " +
- "or the broker is restarted.");
+ "NOTE: These options modify the configuration file. " +
+ "Changes only take effect automatically if LogWatch is enabled.");
+ Label noteLabel2 = _toolkit.createLabel(_headerComposite,
+ "A Logger set to a non-inherited Level in the Runtime tab " +
+ "will retain that value after the configuration is reloaded.");
GridData gridData = new GridData(SWT.FILL, SWT.FILL, false, true);
noteLabel.setLayoutData(gridData);
+ gridData = new GridData(SWT.FILL, SWT.FILL, false, true);
+ noteLabel2.setLayoutData(gridData);
Group configFileLoggerLevelsGroup = new Group(_paramsComposite, SWT.SHADOW_NONE);
configFileLoggerLevelsGroup.setBackground(_paramsComposite.getBackground());
diff --git a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/logging/RuntimeTabControl.java b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/logging/RuntimeTabControl.java
index 012c22e6de..0a7f669a5f 100644
--- a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/logging/RuntimeTabControl.java
+++ b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/logging/RuntimeTabControl.java
@@ -26,6 +26,7 @@ import java.util.HashMap;
import javax.management.MBeanServerConnection;
import javax.management.MBeanServerInvocationHandler;
import javax.management.openmbean.CompositeData;
+import javax.management.openmbean.CompositeDataSupport;
import javax.management.openmbean.TabularDataSupport;
import static org.apache.qpid.management.ui.Constants.FONT_BOLD;
@@ -37,7 +38,10 @@ import org.apache.qpid.management.ui.jmx.JMXManagedObject;
import org.apache.qpid.management.ui.jmx.MBeanUtility;
import org.apache.qpid.management.ui.views.TabControl;
import org.apache.qpid.management.ui.views.ViewUtility;
+import org.eclipse.jface.viewers.IColorProvider;
import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
@@ -46,12 +50,15 @@ import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
@@ -78,10 +85,11 @@ public class RuntimeTabControl extends TabControl
private Label _runtimeRootLoggerLevelLabel = null;
private String[] _availableLoggerLevels;
private TabularDataSupport _runtimeLoggerLevels = null;
+ private ArrayList<String> _configFileLoggerNames = new ArrayList<String>();
private LoggingManagement _lmmb;
- static final String LOGGER_NAME = LoggingManagement.COMPOSITE_ITEM_NAMES[0];
- static final String LOGGER_LEVEL = LoggingManagement.COMPOSITE_ITEM_NAMES[1];
+ private static final String LOGGER_NAME = LoggingManagement.COMPOSITE_ITEM_NAMES[0];
+ private static final String LOGGER_LEVEL = LoggingManagement.COMPOSITE_ITEM_NAMES[1];
public RuntimeTabControl(TabFolder tabFolder, JMXManagedObject mbean, MBeanServerConnection mbsc)
{
@@ -148,6 +156,26 @@ public class RuntimeTabControl extends TabControl
MBeanUtility.handleException(_mbean, e2);
}
+
+ try
+ {
+ TabularDataSupport confLoggers = (TabularDataSupport) _lmmb.viewConfigFileLoggerLevels();
+ ArrayList<String> confLoggerNames = new ArrayList<String>();
+
+ for(Object obj : confLoggers.values())
+ {
+ CompositeData comp = (CompositeData) obj;
+ confLoggerNames.add((String) comp.get(LOGGER_NAME));
+ }
+
+ _configFileLoggerNames = confLoggerNames;
+ }
+ catch(Exception e2)
+ {
+ //dont signal the failure, just dont highlight the config file loggers, empty the existing list.
+ _configFileLoggerNames.clear();
+ }
+
_runtimeRootLoggerLevelLabel.setText(String.valueOf(runtimeRootLoggerLevel));
_tableViewer.setInput(_runtimeLoggerLevels);
@@ -174,8 +202,13 @@ public class RuntimeTabControl extends TabControl
Label noteLabel = _toolkit.createLabel(_headerComposite,
"NOTE: These options modify only the live runtime settings. " +
"Non-default values will be lost following broker restart.");
+ Label noteLabel2 = _toolkit.createLabel(_headerComposite,
+ "Loggers currently defined in the configuration file are " +
+ "highlighted. The other Loggers inherit a Level by default.");
GridData gridData = new GridData(SWT.FILL, SWT.FILL, false, true);
noteLabel.setLayoutData(gridData);
+ gridData = new GridData(SWT.FILL, SWT.FILL, false, true);
+ noteLabel2.setLayoutData(gridData);
Group effectiveRuntimeLoggerLevelsGroup = new Group(_paramsComposite, SWT.SHADOW_NONE);
effectiveRuntimeLoggerLevelsGroup.setBackground(_paramsComposite.getBackground());
@@ -239,7 +272,7 @@ public class RuntimeTabControl extends TabControl
}
_tableViewer.setContentProvider(new LoggingTableContentProvider());
- _tableViewer.setLabelProvider(new LoggingTableLabelProvider());
+ _tableViewer.setLabelProvider(new RuntimeLoggingTableLabelProvider());
_tableViewer.setSorter(tableSorter);
_table.setSortColumn(_table.getColumn(0));
_table.setSortDirection(SWT.UP);
@@ -510,4 +543,53 @@ public class RuntimeTabControl extends TabControl
shell.open();
}
+
+ /**
+ * Label Provider class for the RuntimeLoggers table viewer
+ */
+ public class RuntimeLoggingTableLabelProvider extends LabelProvider implements ITableLabelProvider, IColorProvider
+ {
+
+ @Override
+ public String getColumnText(Object element, int columnIndex)
+ {
+ switch (columnIndex)
+ {
+ case 0 : // logger name column
+ return (String) ((CompositeDataSupport) element).get(LOGGER_NAME);
+ case 1 : // logger level column
+ return (String) ((CompositeDataSupport) element).get(LOGGER_LEVEL);
+ default :
+ return "-";
+ }
+ }
+
+ @Override
+ public Image getColumnImage(Object element, int columnIndex)
+ {
+ return null;
+ }
+
+ @Override
+ public Color getBackground(Object element)
+ {
+ return null;
+ }
+
+ @Override
+ public Color getForeground(Object element)
+ {
+ String loggerName = (String) ((CompositeData) element).get(LOGGER_NAME);
+ if(_configFileLoggerNames.contains(loggerName))
+ {
+ return Display.getCurrent().getSystemColor(SWT.COLOR_BLUE);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+
+ }
}