http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/chainsaw/ChainsawAppenderHandler.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/ChainsawAppenderHandler.java b/src/main/java/org/apache/log4j/chainsaw/ChainsawAppenderHandler.java index bbdc7bc..2c6924b 100644 --- a/src/main/java/org/apache/log4j/chainsaw/ChainsawAppenderHandler.java +++ b/src/main/java/org/apache/log4j/chainsaw/ChainsawAppenderHandler.java @@ -16,333 +16,330 @@ */ package org.apache.log4j.chainsaw; -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import javax.swing.event.EventListenerList; import org.apache.log4j.AppenderSkeleton; import org.apache.log4j.LogManager; import org.apache.log4j.helpers.Constants; import org.apache.log4j.net.SocketReceiver; import org.apache.log4j.rule.ExpressionRule; import org.apache.log4j.rule.Rule; -import org.apache.log4j.spi.LoggingEvent; import org.apache.log4j.spi.LoggerRepositoryEx; +import org.apache.log4j.spi.LoggingEvent; import org.apache.log4j.spi.LoggingEventFieldResolver; +import javax.swing.event.EventListenerList; +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; +import java.util.*; + /** * A handler class that either extends a particular appender hierarchy or can be * bound into the Log4j appender framework, and queues events, to be later * dispatched to registered/interested parties. - * + * * @author Scott Deboy <sde...@apache.org> * @author Paul Smith <psm...@apache.org> - * */ public class ChainsawAppenderHandler extends AppenderSkeleton { - private static final String DEFAULT_IDENTIFIER = "Unknown"; - private final Object mutex = new Object(); - private int sleepInterval = 1000; - private EventListenerList listenerList = new EventListenerList(); - private double dataRate = 0.0; - private String identifierExpression; - private final LoggingEventFieldResolver resolver = LoggingEventFieldResolver - .getInstance(); - private PropertyChangeSupport propertySupport = new PropertyChangeSupport( - this); - private Map<String, Rule> customExpressionRules = new HashMap<>(); - - /** - * NOTE: This variable needs to be physically located LAST, because - * of the initialization sequence, the WorkQueue constructor starts a thread - * which ends up needing some reference to fields created in ChainsawAppenderHandler (outer instance) - * which may not have been created yet. Becomes a race condition, and therefore - * this field initialization should be kept last. - */ - private WorkQueue worker = new WorkQueue(); - - public ChainsawAppenderHandler(final ChainsawAppender appender) { - super(true); - appender.setAppender(this); - } - - public ChainsawAppenderHandler() { - super(true); - } - - public void setIdentifierExpression(String identifierExpression) { - synchronized (mutex) { - this.identifierExpression = identifierExpression; - mutex.notify(); + private static final String DEFAULT_IDENTIFIER = "Unknown"; + private final Object mutex = new Object(); + private int sleepInterval = 1000; + private EventListenerList listenerList = new EventListenerList(); + private double dataRate = 0.0; + private String identifierExpression; + private final LoggingEventFieldResolver resolver = LoggingEventFieldResolver + .getInstance(); + private PropertyChangeSupport propertySupport = new PropertyChangeSupport( + this); + private Map<String, Rule> customExpressionRules = new HashMap<>(); + + /** + * NOTE: This variable needs to be physically located LAST, because + * of the initialization sequence, the WorkQueue constructor starts a thread + * which ends up needing some reference to fields created in ChainsawAppenderHandler (outer instance) + * which may not have been created yet. Becomes a race condition, and therefore + * this field initialization should be kept last. + */ + private WorkQueue worker = new WorkQueue(); + + public ChainsawAppenderHandler(final ChainsawAppender appender) { + super(true); + appender.setAppender(this); } - } - - public String getIdentifierExpression() { - return identifierExpression; - } - - public void addCustomEventBatchListener(String identifier, - EventBatchListener l) throws IllegalArgumentException { - customExpressionRules.put(identifier, ExpressionRule.getRule(identifier)); - listenerList.add(EventBatchListener.class, l); - } - - public void addEventBatchListener(EventBatchListener l) { - listenerList.add(EventBatchListener.class, l); - } - - public void removeEventBatchListener(EventBatchListener l) { - listenerList.remove(EventBatchListener.class, l); - } - - public void append(LoggingEvent event) { - worker.enqueue(event); - } - - public void close() {} - - public boolean requiresLayout() { - return false; - } - - public int getQueueInterval() { - return sleepInterval; - } - - public void setQueueInterval(int interval) { - sleepInterval = interval; - } - - /** - * Determines an appropriate title for the Tab for the Tab Pane by locating a - * the hostname property - * - * @param e - * @return identifier - */ - String getTabIdentifier(LoggingEvent e) { - String ident = resolver.applyFields(identifierExpression, e); - return ((ident != null) ? ident : DEFAULT_IDENTIFIER); - } - - /** - * A little test bed - * - * @param args - */ - public static void main(String[] args) throws InterruptedException { - ChainsawAppenderHandler handler = new ChainsawAppenderHandler(); - handler.addEventBatchListener(new EventBatchListener() { - public String getInterestedIdentifier() { - return null; - } - - public void receiveEventBatch(String identifier, List<LoggingEvent> events) { - System.out.println("received " + events.size()); - } - }); - LogManager.getRootLogger().addAppender(handler); - SocketReceiver receiver = new SocketReceiver(4445); - ((LoggerRepositoryEx) LogManager.getLoggerRepository()).getPluginRegistry().addPlugin(receiver); - receiver.activateOptions(); - Thread.sleep(60000); - } - - /** - * Exposes the current Data rate calculated. This is periodically updated by - * an internal Thread as is the number of events that have been processed, and - * dispatched to all listeners since the last sample period divided by the - * number of seconds since the last sample period. - * - * This method fires a PropertyChange event so listeners can monitor the rate - * - * @return double # of events processed per second - */ - public double getDataRate() { - return dataRate; - } - - /** - * @param dataRate - */ - void setDataRate(double dataRate) { - double oldValue = this.dataRate; - this.dataRate = dataRate; - propertySupport.firePropertyChange("dataRate", oldValue, - this.dataRate); - } - - /** - * @param listener - */ - public synchronized void addPropertyChangeListener( - PropertyChangeListener listener) { - propertySupport.addPropertyChangeListener(listener); - } - - /** - * @param propertyName - * @param listener - */ - public synchronized void addPropertyChangeListener(String propertyName, - PropertyChangeListener listener) { - propertySupport.addPropertyChangeListener(propertyName, listener); - } - - /** - * @param listener - */ - public synchronized void removePropertyChangeListener( - PropertyChangeListener listener) { - propertySupport.removePropertyChangeListener(listener); - } - - /** - * @param propertyName - * @param listener - */ - public synchronized void removePropertyChangeListener(String propertyName, - PropertyChangeListener listener) { - propertySupport.removePropertyChangeListener(propertyName, listener); - } - - /** - * Queue of Events are placed in here, which are picked up by an asychronous - * thread. The WorkerThread looks for events once a second and processes all - * events accumulated during that time.. - */ - class WorkQueue { - final ArrayList<LoggingEvent> queue = new ArrayList<>(); - Thread workerThread; - - protected WorkQueue() { - workerThread = new WorkerThread(); - workerThread.start(); + + public ChainsawAppenderHandler() { + super(true); + } + + public void setIdentifierExpression(String identifierExpression) { + synchronized (mutex) { + this.identifierExpression = identifierExpression; + mutex.notify(); + } + } + + public String getIdentifierExpression() { + return identifierExpression; } - public final void enqueue(LoggingEvent event) { - synchronized (mutex) { - queue.add(event); - mutex.notify(); - } + public void addCustomEventBatchListener(String identifier, + EventBatchListener l) throws IllegalArgumentException { + customExpressionRules.put(identifier, ExpressionRule.getRule(identifier)); + listenerList.add(EventBatchListener.class, l); } - public final void stop() { - synchronized (mutex) { - workerThread.interrupt(); - } + public void addEventBatchListener(EventBatchListener l) { + listenerList.add(EventBatchListener.class, l); + } + + public void removeEventBatchListener(EventBatchListener l) { + listenerList.remove(EventBatchListener.class, l); + } + + public void append(LoggingEvent event) { + worker.enqueue(event); + } + + public void close() { + } + + public boolean requiresLayout() { + return false; + } + + public int getQueueInterval() { + return sleepInterval; + } + + public void setQueueInterval(int interval) { + sleepInterval = interval; + } + + /** + * Determines an appropriate title for the Tab for the Tab Pane by locating a + * the hostname property + * + * @param e + * @return identifier + */ + String getTabIdentifier(LoggingEvent e) { + String ident = resolver.applyFields(identifierExpression, e); + return ((ident != null) ? ident : DEFAULT_IDENTIFIER); } /** - * The worker thread converts each queued event to a vector and forwards the - * vector on to the UI. + * A little test bed + * + * @param args */ - private class WorkerThread extends Thread { - public WorkerThread() { - super("Chainsaw-WorkerThread"); - setDaemon(true); - setPriority(Thread.NORM_PRIORITY - 1); - } - - public void run() { - List<LoggingEvent> innerList = new ArrayList<>(); - while (true) { - long timeStart = System.currentTimeMillis(); - synchronized (mutex) { - try { - while ((queue.size() == 0) || (identifierExpression == null)) { - setDataRate(0); - mutex.wait(); - } - if (queue.size() > 0) { - innerList.addAll(queue); - queue.clear(); - } + public static void main(String[] args) throws InterruptedException { + ChainsawAppenderHandler handler = new ChainsawAppenderHandler(); + handler.addEventBatchListener(new EventBatchListener() { + public String getInterestedIdentifier() { + return null; } - catch (InterruptedException ie) {} - } - int size = innerList.size(); - if (size > 0) { - Iterator<LoggingEvent> iter = innerList.iterator(); - ChainsawEventBatch eventBatch = new ChainsawEventBatch(); - while (iter.hasNext()) { - LoggingEvent e = iter.next(); - // attempt to set the host name (without port), from - // remoteSourceInfo - // if 'hostname' property not provided - if (e.getProperty(Constants.HOSTNAME_KEY) == null) { - String remoteHost = e - .getProperty(ChainsawConstants.LOG4J_REMOTEHOST_KEY); - if (remoteHost != null) { - int colonIndex = remoteHost.indexOf(":"); - if (colonIndex == -1) { - colonIndex = remoteHost.length(); - } - e.setProperty(Constants.HOSTNAME_KEY, remoteHost.substring(0, - colonIndex)); - } - } - for (Object o : customExpressionRules.entrySet()) { - Map.Entry entry = (Map.Entry) o; - Rule rule = (Rule) entry.getValue(); - if (rule.evaluate(e, null)) { - eventBatch.addEvent((String) entry.getKey(), e); - } - } - eventBatch.addEvent(getTabIdentifier(e), e); + + public void receiveEventBatch(String identifier, List<LoggingEvent> events) { + System.out.println("received " + events.size()); + } + }); + LogManager.getRootLogger().addAppender(handler); + SocketReceiver receiver = new SocketReceiver(4445); + ((LoggerRepositoryEx) LogManager.getLoggerRepository()).getPluginRegistry().addPlugin(receiver); + receiver.activateOptions(); + Thread.sleep(60000); + } + + /** + * Exposes the current Data rate calculated. This is periodically updated by + * an internal Thread as is the number of events that have been processed, and + * dispatched to all listeners since the last sample period divided by the + * number of seconds since the last sample period. + * <p> + * This method fires a PropertyChange event so listeners can monitor the rate + * + * @return double # of events processed per second + */ + public double getDataRate() { + return dataRate; + } + + /** + * @param dataRate + */ + void setDataRate(double dataRate) { + double oldValue = this.dataRate; + this.dataRate = dataRate; + propertySupport.firePropertyChange("dataRate", oldValue, + this.dataRate); + } + + /** + * @param listener + */ + public synchronized void addPropertyChangeListener( + PropertyChangeListener listener) { + propertySupport.addPropertyChangeListener(listener); + } + + /** + * @param propertyName + * @param listener + */ + public synchronized void addPropertyChangeListener(String propertyName, + PropertyChangeListener listener) { + propertySupport.addPropertyChangeListener(propertyName, listener); + } + + /** + * @param listener + */ + public synchronized void removePropertyChangeListener( + PropertyChangeListener listener) { + propertySupport.removePropertyChangeListener(listener); + } + + /** + * @param propertyName + * @param listener + */ + public synchronized void removePropertyChangeListener(String propertyName, + PropertyChangeListener listener) { + propertySupport.removePropertyChangeListener(propertyName, listener); + } + + /** + * Queue of Events are placed in here, which are picked up by an asychronous + * thread. The WorkerThread looks for events once a second and processes all + * events accumulated during that time.. + */ + class WorkQueue { + final ArrayList<LoggingEvent> queue = new ArrayList<>(); + Thread workerThread; + + protected WorkQueue() { + workerThread = new WorkerThread(); + workerThread.start(); + } + + public final void enqueue(LoggingEvent event) { + synchronized (mutex) { + queue.add(event); + mutex.notify(); } - dispatchEventBatch(eventBatch); - innerList.clear(); - } - if (getQueueInterval() > 1000) { - try { - synchronized (this) { - wait(getQueueInterval()); - } + } + + public final void stop() { + synchronized (mutex) { + workerThread.interrupt(); } - catch (InterruptedException ie) {} - } else { - Thread.yield(); - } - if (size == 0) { - setDataRate(0.0); - } else { - long timeEnd = System.currentTimeMillis(); - long diffInSeconds = (timeEnd - timeStart) / 1000; - double rate = (((double) size) / diffInSeconds); - setDataRate(rate); - } } - } - - /** - * Dispatches the event batches contents to all the interested parties by - * iterating over each identifier and dispatching the - * ChainsawEventBatchEntry object to each listener that is interested. - * - * @param eventBatch - */ - private void dispatchEventBatch(ChainsawEventBatch eventBatch) { - EventBatchListener[] listeners = listenerList - .getListeners(EventBatchListener.class); - for (Iterator<String> iter = eventBatch.identifierIterator(); iter.hasNext();) { - String identifier = iter.next(); - List<LoggingEvent> eventList = null; - for (EventBatchListener listener : listeners) { - if ((listener.getInterestedIdentifier() == null) - || listener.getInterestedIdentifier().equals(identifier)) { - if (eventList == null) { - eventList = eventBatch.entrySet(identifier); - } - listener.receiveEventBatch(identifier, eventList); + + /** + * The worker thread converts each queued event to a vector and forwards the + * vector on to the UI. + */ + private class WorkerThread extends Thread { + public WorkerThread() { + super("Chainsaw-WorkerThread"); + setDaemon(true); + setPriority(Thread.NORM_PRIORITY - 1); + } + + public void run() { + List<LoggingEvent> innerList = new ArrayList<>(); + while (true) { + long timeStart = System.currentTimeMillis(); + synchronized (mutex) { + try { + while ((queue.size() == 0) || (identifierExpression == null)) { + setDataRate(0); + mutex.wait(); + } + if (queue.size() > 0) { + innerList.addAll(queue); + queue.clear(); + } + } catch (InterruptedException ie) { + } + } + int size = innerList.size(); + if (size > 0) { + Iterator<LoggingEvent> iter = innerList.iterator(); + ChainsawEventBatch eventBatch = new ChainsawEventBatch(); + while (iter.hasNext()) { + LoggingEvent e = iter.next(); + // attempt to set the host name (without port), from + // remoteSourceInfo + // if 'hostname' property not provided + if (e.getProperty(Constants.HOSTNAME_KEY) == null) { + String remoteHost = e + .getProperty(ChainsawConstants.LOG4J_REMOTEHOST_KEY); + if (remoteHost != null) { + int colonIndex = remoteHost.indexOf(":"); + if (colonIndex == -1) { + colonIndex = remoteHost.length(); + } + e.setProperty(Constants.HOSTNAME_KEY, remoteHost.substring(0, + colonIndex)); + } + } + for (Object o : customExpressionRules.entrySet()) { + Map.Entry entry = (Map.Entry) o; + Rule rule = (Rule) entry.getValue(); + if (rule.evaluate(e, null)) { + eventBatch.addEvent((String) entry.getKey(), e); + } + } + eventBatch.addEvent(getTabIdentifier(e), e); + } + dispatchEventBatch(eventBatch); + innerList.clear(); + } + if (getQueueInterval() > 1000) { + try { + synchronized (this) { + wait(getQueueInterval()); + } + } catch (InterruptedException ie) { + } + } else { + Thread.yield(); + } + if (size == 0) { + setDataRate(0.0); + } else { + long timeEnd = System.currentTimeMillis(); + long diffInSeconds = (timeEnd - timeStart) / 1000; + double rate = (((double) size) / diffInSeconds); + setDataRate(rate); + } + } + } + + /** + * Dispatches the event batches contents to all the interested parties by + * iterating over each identifier and dispatching the + * ChainsawEventBatchEntry object to each listener that is interested. + * + * @param eventBatch + */ + private void dispatchEventBatch(ChainsawEventBatch eventBatch) { + EventBatchListener[] listeners = listenerList + .getListeners(EventBatchListener.class); + for (Iterator<String> iter = eventBatch.identifierIterator(); iter.hasNext(); ) { + String identifier = iter.next(); + List<LoggingEvent> eventList = null; + for (EventBatchListener listener : listeners) { + if ((listener.getInterestedIdentifier() == null) + || listener.getInterestedIdentifier().equals(identifier)) { + if (eventList == null) { + eventList = eventBatch.entrySet(identifier); + } + listener.receiveEventBatch(identifier, eventList); + } + } + } } - } } - } } - } }
http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/chainsaw/ChainsawColumns.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/ChainsawColumns.java b/src/main/java/org/apache/log4j/chainsaw/ChainsawColumns.java index faff682..037fd24 100644 --- a/src/main/java/org/apache/log4j/chainsaw/ChainsawColumns.java +++ b/src/main/java/org/apache/log4j/chainsaw/ChainsawColumns.java @@ -5,9 +5,9 @@ * 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. @@ -17,77 +17,75 @@ package org.apache.log4j.chainsaw; -import java.awt.Cursor; -import java.awt.Point; -import java.awt.Toolkit; +import org.apache.log4j.chainsaw.icons.ChainsawIcons; + +import javax.swing.*; +import java.awt.*; import java.util.ArrayList; import java.util.List; -import javax.swing.ImageIcon; - -import org.apache.log4j.chainsaw.icons.ChainsawIcons; - /** * @author Paul Smith <psm...@apache.org> - * */ public class ChainsawColumns { - private static final List<String> columnNames = new ArrayList<>(); + private static final List<String> columnNames = new ArrayList<>(); + + static { + columnNames.add(ChainsawConstants.LOGGER_COL_NAME); + columnNames.add(ChainsawConstants.LOG4J_MARKER_COL_NAME_LOWERCASE.toUpperCase()); //add uppercase col name + columnNames.add(ChainsawConstants.TIMESTAMP_COL_NAME); + columnNames.add(ChainsawConstants.LEVEL_COL_NAME); + columnNames.add(ChainsawConstants.THREAD_COL_NAME); + columnNames.add(ChainsawConstants.MESSAGE_COL_NAME); + columnNames.add(ChainsawConstants.NDC_COL_NAME); + columnNames.add(ChainsawConstants.THROWABLE_COL_NAME); + columnNames.add(ChainsawConstants.CLASS_COL_NAME); + columnNames.add(ChainsawConstants.METHOD_COL_NAME); + columnNames.add(ChainsawConstants.FILE_COL_NAME); + columnNames.add(ChainsawConstants.MILLIS_DELTA_COL_NAME_LOWERCASE.toUpperCase()); //add uppercase col name + columnNames.add(ChainsawConstants.LINE_COL_NAME); - static { - columnNames.add(ChainsawConstants.LOGGER_COL_NAME); - columnNames.add(ChainsawConstants.LOG4J_MARKER_COL_NAME_LOWERCASE.toUpperCase()); //add uppercase col name - columnNames.add(ChainsawConstants.TIMESTAMP_COL_NAME); - columnNames.add(ChainsawConstants.LEVEL_COL_NAME); - columnNames.add(ChainsawConstants.THREAD_COL_NAME); - columnNames.add(ChainsawConstants.MESSAGE_COL_NAME); - columnNames.add(ChainsawConstants.NDC_COL_NAME); - columnNames.add(ChainsawConstants.THROWABLE_COL_NAME); - columnNames.add(ChainsawConstants.CLASS_COL_NAME); - columnNames.add(ChainsawConstants.METHOD_COL_NAME); - columnNames.add(ChainsawConstants.FILE_COL_NAME); - columnNames.add(ChainsawConstants.MILLIS_DELTA_COL_NAME_LOWERCASE.toUpperCase()); //add uppercase col name - columnNames.add(ChainsawConstants.LINE_COL_NAME); + //NOTE: ID must ALWAYS be last field because the model adds this value itself as an identifier to the end of the consructed vector + columnNames.add(ChainsawConstants.ID_COL_NAME); + } - //NOTE: ID must ALWAYS be last field because the model adds this value itself as an identifier to the end of the consructed vector - columnNames.add(ChainsawConstants.ID_COL_NAME); - } + public static final int INDEX_LOGGER_COL_NAME = 1; + public static final int INDEX_LOG4J_MARKER_COL_NAME = 2; + public static final int INDEX_TIMESTAMP_COL_NAME = 3; + public static final int INDEX_LEVEL_COL_NAME = 4; + public static final int INDEX_THREAD_COL_NAME = 5; + public static final int INDEX_MESSAGE_COL_NAME = 6; + public static final int INDEX_NDC_COL_NAME = 7; + public static final int INDEX_THROWABLE_COL_NAME = 8; + public static final int INDEX_CLASS_COL_NAME = 9; + public static final int INDEX_METHOD_COL_NAME = 10; + public static final int INDEX_FILE_COL_NAME = 11; + public static final int INDEX_LINE_COL_NAME = 12; + public static final int INDEX_MILLIS_DELTA_COL_NAME = 13; + public static final int INDEX_ID_COL_NAME = 14; - public static final int INDEX_LOGGER_COL_NAME = 1; - public static final int INDEX_LOG4J_MARKER_COL_NAME = 2; - public static final int INDEX_TIMESTAMP_COL_NAME = 3; - public static final int INDEX_LEVEL_COL_NAME = 4; - public static final int INDEX_THREAD_COL_NAME = 5; - public static final int INDEX_MESSAGE_COL_NAME = 6; - public static final int INDEX_NDC_COL_NAME = 7; - public static final int INDEX_THROWABLE_COL_NAME = 8; - public static final int INDEX_CLASS_COL_NAME = 9; - public static final int INDEX_METHOD_COL_NAME = 10; - public static final int INDEX_FILE_COL_NAME = 11; - public static final int INDEX_LINE_COL_NAME = 12; - public static final int INDEX_MILLIS_DELTA_COL_NAME = 13; - public static final int INDEX_ID_COL_NAME = 14; + public static final Cursor CURSOR_FOCUS_ON; - public static final Cursor CURSOR_FOCUS_ON; - static{ - CURSOR_FOCUS_ON = Toolkit.getDefaultToolkit().createCustomCursor(new ImageIcon(ChainsawIcons.WINDOW_ICON).getImage(), new Point(3,3), "FocusOn"); - } + static { + CURSOR_FOCUS_ON = Toolkit.getDefaultToolkit().createCustomCursor(new ImageIcon(ChainsawIcons.WINDOW_ICON).getImage(), new Point(3, 3), "FocusOn"); + } - private ChainsawColumns() { - } + private ChainsawColumns() { + } - public static List<String> getColumnsNames() { - return columnNames; - } + public static List<String> getColumnsNames() { + return columnNames; + } - /** - * Given the index which matches one of the static constants in this class, returns the resolved - * Column name as a string label. - * @param columnIndex (note this is a 1 based collection) - * @return column name - */ - public static String getColumnName(int columnIndex) { - return getColumnsNames().get(columnIndex - 1).toString(); - } + /** + * Given the index which matches one of the static constants in this class, returns the resolved + * Column name as a string label. + * + * @param columnIndex (note this is a 1 based collection) + * @return column name + */ + public static String getColumnName(int columnIndex) { + return getColumnsNames().get(columnIndex - 1).toString(); + } } http://git-wip-us.apache.org/repos/asf/logging-chainsaw/blob/96ebd9ad/src/main/java/org/apache/log4j/chainsaw/ChainsawConstants.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/log4j/chainsaw/ChainsawConstants.java b/src/main/java/org/apache/log4j/chainsaw/ChainsawConstants.java index 8448958..e7cdf92 100644 --- a/src/main/java/org/apache/log4j/chainsaw/ChainsawConstants.java +++ b/src/main/java/org/apache/log4j/chainsaw/ChainsawConstants.java @@ -5,9 +5,9 @@ * 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. @@ -17,92 +17,91 @@ package org.apache.log4j.chainsaw; -import java.awt.Color; +import java.awt.*; import java.net.URL; /** - * * Constants used throught Chainsaw. - * + * * @author Paul Smith <psm...@apache.org> * @author Scott Deboy <sde...@apache.org> - * */ public class ChainsawConstants { - private ChainsawConstants(){} - - public static final int MILLIS_DELTA_RENDERING_HEIGHT_MAX = 50; - public static final float MILLIS_DELTA_RENDERING_FACTOR = .002F; - - public static final String DEFAULT_COLOR_RULE_NAME = "Default"; - public static final Color COLOR_DEFAULT_BACKGROUND = new Color(255,255,255); - public static final Color COLOR_DEFAULT_FOREGROUND = Color.BLACK; - - //top, bottom left and right border are all 2 - public static final int TABLE_BORDER_WIDTH = 2; - //JTable defines its default height as 16, plus top & bottom borders - public static final int DEFAULT_ROW_HEIGHT = 16 + (TABLE_BORDER_WIDTH * 2); - public static final Color FIND_LOGGER_BACKGROUND = new Color(213, 226, 235); - public static final Color FIND_LOGGER_FOREGROUND = Color.BLACK; - - public static final Color INVALID_EXPRESSION_BACKGROUND = new Color(251, 186, 186); - - public static final Color COLOR_ODD_ROW_BACKGROUND = new Color(227, 227, 227); - public static final Color COLOR_ODD_ROW_FOREGROUND = Color.BLACK; - - public static final Color COLOR_EVEN_ROW_BACKGROUND = COLOR_DEFAULT_BACKGROUND; - public static final Color COLOR_EVEN_ROW_FOREGROUND = Color.BLACK; - - public static final URL WELCOME_URL = ChainsawConstants.class.getClassLoader().getResource( - "org/apache/log4j/chainsaw/WelcomePanel.html"); - - public static final URL EXAMPLE_CONFIG_URL = - ChainsawConstants.class.getClassLoader().getResource("org/apache/log4j/chainsaw/log4j-receiver-sample.xml"); - - public static final URL TUTORIAL_URL = - ChainsawConstants.class.getClassLoader().getResource("org/apache/log4j/chainsaw/help/tutorial.html"); - public static final URL RELEASE_NOTES_URL = - ChainsawConstants.class.getClassLoader().getResource("org/apache/log4j/chainsaw/help/release-notes.html"); - - static final String MAIN_PANEL = "panel"; - static final String LOWER_PANEL = "lower"; - static final String UPPER_PANEL = "upper"; - static final String EMPTY_STRING = ""; - static final String FILTERS_EXTENSION = ".filters"; - static final String SETTINGS_EXTENSION = ".settings"; - - //COLUMN NAMES - static final String LOGGER_COL_NAME = "LOGGER"; - static final String LOG4J_MARKER_COL_NAME_LOWERCASE = "marker"; - static final String TIMESTAMP_COL_NAME = "TIMESTAMP"; - static final String LEVEL_COL_NAME = "LEVEL"; - static final String THREAD_COL_NAME = "THREAD"; - static final String MESSAGE_COL_NAME = "MESSAGE"; - static final String NDC_COL_NAME = "NDC"; - static final String THROWABLE_COL_NAME = "THROWABLE"; - static final String CLASS_COL_NAME = "CLASS"; - static final String METHOD_COL_NAME = "METHOD"; - static final String FILE_COL_NAME = "FILE"; - static final String LINE_COL_NAME = "LINE"; - static final String PROPERTIES_COL_NAME = "PROPERTIES"; - static final String MILLIS_DELTA_COL_NAME_LOWERCASE = "millisdelta"; - static final String ID_COL_NAME = "ID"; - - //none is not a real column name, but is used by filters as a way to apply no filter for colors or display - static final String NONE_COL_NAME = "None"; - static final String LOG4J_REMOTEHOST_KEY = "log4j.remoteSourceInfo"; - static final String UNKNOWN_TAB_NAME = "Unknown"; - static final String GLOBAL_MATCH = "*"; - public static final String DETAIL_CONTENT_TYPE = "text/html"; - - static final String LEVEL_DISPLAY = "level.display"; - static final String LEVEL_DISPLAY_ICONS = "icons"; - static final String LEVEL_DISPLAY_TEXT = "text"; - - - static final String DATETIME_FORMAT = "EEE MMM dd HH:mm:ss z yyyy"; - -// TODO come up with a better page not found url - public static final URL URL_PAGE_NOT_FOUND = WELCOME_URL; + private ChainsawConstants() { + } + + public static final int MILLIS_DELTA_RENDERING_HEIGHT_MAX = 50; + public static final float MILLIS_DELTA_RENDERING_FACTOR = .002F; + + public static final String DEFAULT_COLOR_RULE_NAME = "Default"; + public static final Color COLOR_DEFAULT_BACKGROUND = new Color(255, 255, 255); + public static final Color COLOR_DEFAULT_FOREGROUND = Color.BLACK; + + //top, bottom left and right border are all 2 + public static final int TABLE_BORDER_WIDTH = 2; + //JTable defines its default height as 16, plus top & bottom borders + public static final int DEFAULT_ROW_HEIGHT = 16 + (TABLE_BORDER_WIDTH * 2); + public static final Color FIND_LOGGER_BACKGROUND = new Color(213, 226, 235); + public static final Color FIND_LOGGER_FOREGROUND = Color.BLACK; + + public static final Color INVALID_EXPRESSION_BACKGROUND = new Color(251, 186, 186); + + public static final Color COLOR_ODD_ROW_BACKGROUND = new Color(227, 227, 227); + public static final Color COLOR_ODD_ROW_FOREGROUND = Color.BLACK; + + public static final Color COLOR_EVEN_ROW_BACKGROUND = COLOR_DEFAULT_BACKGROUND; + public static final Color COLOR_EVEN_ROW_FOREGROUND = Color.BLACK; + + public static final URL WELCOME_URL = ChainsawConstants.class.getClassLoader().getResource( + "org/apache/log4j/chainsaw/WelcomePanel.html"); + + public static final URL EXAMPLE_CONFIG_URL = + ChainsawConstants.class.getClassLoader().getResource("org/apache/log4j/chainsaw/log4j-receiver-sample.xml"); + + public static final URL TUTORIAL_URL = + ChainsawConstants.class.getClassLoader().getResource("org/apache/log4j/chainsaw/help/tutorial.html"); + public static final URL RELEASE_NOTES_URL = + ChainsawConstants.class.getClassLoader().getResource("org/apache/log4j/chainsaw/help/release-notes.html"); + + static final String MAIN_PANEL = "panel"; + static final String LOWER_PANEL = "lower"; + static final String UPPER_PANEL = "upper"; + static final String EMPTY_STRING = ""; + static final String FILTERS_EXTENSION = ".filters"; + static final String SETTINGS_EXTENSION = ".settings"; + + //COLUMN NAMES + static final String LOGGER_COL_NAME = "LOGGER"; + static final String LOG4J_MARKER_COL_NAME_LOWERCASE = "marker"; + static final String TIMESTAMP_COL_NAME = "TIMESTAMP"; + static final String LEVEL_COL_NAME = "LEVEL"; + static final String THREAD_COL_NAME = "THREAD"; + static final String MESSAGE_COL_NAME = "MESSAGE"; + static final String NDC_COL_NAME = "NDC"; + static final String THROWABLE_COL_NAME = "THROWABLE"; + static final String CLASS_COL_NAME = "CLASS"; + static final String METHOD_COL_NAME = "METHOD"; + static final String FILE_COL_NAME = "FILE"; + static final String LINE_COL_NAME = "LINE"; + static final String PROPERTIES_COL_NAME = "PROPERTIES"; + static final String MILLIS_DELTA_COL_NAME_LOWERCASE = "millisdelta"; + static final String ID_COL_NAME = "ID"; + + //none is not a real column name, but is used by filters as a way to apply no filter for colors or display + static final String NONE_COL_NAME = "None"; + static final String LOG4J_REMOTEHOST_KEY = "log4j.remoteSourceInfo"; + static final String UNKNOWN_TAB_NAME = "Unknown"; + static final String GLOBAL_MATCH = "*"; + public static final String DETAIL_CONTENT_TYPE = "text/html"; + + static final String LEVEL_DISPLAY = "level.display"; + static final String LEVEL_DISPLAY_ICONS = "icons"; + static final String LEVEL_DISPLAY_TEXT = "text"; + + + static final String DATETIME_FORMAT = "EEE MMM dd HH:mm:ss z yyyy"; + + // TODO come up with a better page not found url + public static final URL URL_PAGE_NOT_FOUND = WELCOME_URL; }