You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by gr...@apache.org on 2012/06/02 17:36:26 UTC

svn commit: r1345524 [12/17] - in /logging/log4j/branches/log4j12-bz53299: ./ contribs/ contribs/CekiGulcu/ contribs/EirikLygre/ contribs/JamesHouse/ contribs/Jamie Tsao/ contribs/JimMoore/ contribs/KevinSteppe/ contribs/KitchingSimon/ contribs/LeosLit...

Added: logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/LF5Appender.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/LF5Appender.java?rev=1345524&view=auto
==============================================================================
--- logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/LF5Appender.java (added)
+++ logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/LF5Appender.java Sat Jun  2 15:35:46 2012
@@ -0,0 +1,266 @@
+/*
+ * 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.log4j.lf5;
+
+import java.awt.Toolkit;
+
+import org.apache.log4j.AppenderSkeleton;
+import org.apache.log4j.lf5.viewer.LogBrokerMonitor;
+import org.apache.log4j.spi.LocationInfo;
+import org.apache.log4j.spi.LoggingEvent;
+
+/**
+ * <code>LF5Appender</code> logs events to a swing based logging
+ * console. The swing console supports turning categories on and off,
+ * multiple detail level views, as well as full text searching and many
+ * other capabilties.
+ *
+ * @author Brent Sprecher
+ */
+
+// Contributed by ThoughtWorks Inc.
+
+public class LF5Appender extends AppenderSkeleton {
+  //--------------------------------------------------------------------------
+  // Constants:
+  //--------------------------------------------------------------------------
+
+  //--------------------------------------------------------------------------
+  // Protected Variables:
+  //--------------------------------------------------------------------------
+
+  protected LogBrokerMonitor _logMonitor;
+  protected static LogBrokerMonitor _defaultLogMonitor;
+  protected static AppenderFinalizer _finalizer;
+
+  //--------------------------------------------------------------------------
+  // Private Variables:
+  //--------------------------------------------------------------------------
+
+  //--------------------------------------------------------------------------
+  // Constructors:
+  //--------------------------------------------------------------------------
+
+  /**
+   * Constructs a <code>LF5Appender</code> using the default instance of
+   * the <code>LogBrokerMonitor</code>. This constructor should <bold>always
+   * </bold> be  preferred over the
+   * <code>LF5Appender(LogBrokerMonitor monitor)</code>
+   * constructor, unless you need to spawn additional log monitoring
+   * windows.
+   */
+  public LF5Appender() {
+    this(getDefaultInstance());
+  }
+
+  /**
+   * Constructs a <code>LF5Appender<code> using an instance of
+   * a <code>LogBrokerMonitor<code> supplied by the user. This
+   * constructor should only be used when you need to spawn
+   * additional log monitoring windows.
+   *
+   * @param monitor An instance of a <code>LogBrokerMonitor<code>
+   * created by the user.
+   */
+  public LF5Appender(LogBrokerMonitor monitor) {
+
+    if (monitor != null) {
+      _logMonitor = monitor;
+    }
+  }
+
+  //--------------------------------------------------------------------------
+  // Public Methods:
+  //--------------------------------------------------------------------------
+
+  /**
+   * Appends a <code>LoggingEvent</code> record to the
+   * <code>LF5Appender</code>.
+   * @param event The <code>LoggingEvent</code>
+   * to be appended.
+   */
+  public void append(LoggingEvent event) {
+    // Retrieve the information from the log4j LoggingEvent.
+    String category = event.getLoggerName();
+    String logMessage = event.getRenderedMessage();
+    String nestedDiagnosticContext = event.getNDC();
+    String threadDescription = event.getThreadName();
+    String level = event.getLevel().toString();
+    long time = event.timeStamp;
+    LocationInfo locationInfo = event.getLocationInformation();
+
+    // Add the logging event information to a LogRecord
+    Log4JLogRecord record = new Log4JLogRecord();
+
+    record.setCategory(category);
+    record.setMessage(logMessage);
+    record.setLocation(locationInfo.fullInfo);
+    record.setMillis(time);
+    record.setThreadDescription(threadDescription);
+
+    if (nestedDiagnosticContext != null) {
+      record.setNDC(nestedDiagnosticContext);
+    } else {
+      record.setNDC("");
+    }
+
+    if (event.getThrowableInformation() != null) {
+      record.setThrownStackTrace(event.getThrowableInformation());
+    }
+
+    try {
+      record.setLevel(LogLevel.valueOf(level));
+    } catch (LogLevelFormatException e) {
+      // If the priority level doesn't match one of the predefined
+      // log levels, then set the level to warning.
+      record.setLevel(LogLevel.WARN);
+    }
+
+    if (_logMonitor != null) {
+      _logMonitor.addMessage(record);
+    }
+  }
+
+  /**
+   * This method is an empty implementation of the close() method inherited
+   * from the <code>org.apache.log4j.Appender</code> interface.
+   */
+  public void close() {
+  }
+
+  /**
+   * Returns a value that indicates whether this appender requires a
+   * <code>Layout</code>. This method always returns false.
+   * No layout is required for the <code>LF5Appender</code>.
+   */
+  public boolean requiresLayout() {
+    return false;
+  }
+
+  /**
+   * This method is used to set the property that controls whether
+   * the <code>LogBrokerMonitor</code> is hidden or closed when a user
+   * exits
+   * the monitor. By default, the <code>LogBrokerMonitor</code> will hide
+   * itself when the log window is exited, and the swing thread will
+   * continue to run in the background. If this property is
+   * set to true, the <code>LogBrokerMonitor</code> will call System.exit(0)
+   * and will shut down swing thread and the virtual machine.
+   *
+   * @param callSystemExitOnClose A boolean value indicating whether
+   * to call System.exit(0) when closing the log window.
+   */
+  public void setCallSystemExitOnClose(boolean callSystemExitOnClose) {
+    _logMonitor.setCallSystemExitOnClose(callSystemExitOnClose);
+  }
+
+  /**
+   * The equals method compares two LF5Appenders and determines whether
+   * they are equal. Two <code>Appenders</code> will be considered equal
+   * if, and only if, they both contain references to the same <code>
+   * LogBrokerMonitor</code>.
+   *
+   * @param compareTo A boolean value indicating whether
+   * the two LF5Appenders are equal.
+   */
+  public boolean equals(LF5Appender compareTo) {
+    // If both reference the same LogBrokerMonitor, they are equal.
+    return _logMonitor == compareTo.getLogBrokerMonitor();
+  }
+
+  public LogBrokerMonitor getLogBrokerMonitor() {
+    return _logMonitor;
+  }
+
+  public static void main(String[] args) {
+    new LF5Appender();
+  }
+
+  public void setMaxNumberOfRecords(int maxNumberOfRecords) {
+    _defaultLogMonitor.setMaxNumberOfLogRecords(maxNumberOfRecords);
+  }
+  //--------------------------------------------------------------------------
+  // Protected Methods:
+  //--------------------------------------------------------------------------
+
+  /**
+   * @return The default instance of the <code>LogBrokerMonitor</code>.
+   */
+  protected static synchronized LogBrokerMonitor getDefaultInstance() {
+    if (_defaultLogMonitor == null) {
+      try {
+        _defaultLogMonitor =
+            new LogBrokerMonitor(LogLevel.getLog4JLevels());
+        _finalizer = new AppenderFinalizer(_defaultLogMonitor);
+
+        _defaultLogMonitor.setFrameSize(getDefaultMonitorWidth(),
+            getDefaultMonitorHeight());
+        _defaultLogMonitor.setFontSize(12);
+        _defaultLogMonitor.show();
+
+      } catch (SecurityException e) {
+        _defaultLogMonitor = null;
+      }
+    }
+
+    return _defaultLogMonitor;
+  }
+
+  /**
+   * @return the screen width from Toolkit.getScreenSize()
+   * if possible, otherwise returns 800
+   * @see java.awt.Toolkit
+   */
+  protected static int getScreenWidth() {
+    try {
+      return Toolkit.getDefaultToolkit().getScreenSize().width;
+    } catch (Throwable t) {
+      return 800;
+    }
+  }
+
+  /**
+   * @return the screen height from Toolkit.getScreenSize()
+   * if possible, otherwise returns 600
+   * @see java.awt.Toolkit
+   */
+  protected static int getScreenHeight() {
+    try {
+      return Toolkit.getDefaultToolkit().getScreenSize().height;
+    } catch (Throwable t) {
+      return 600;
+    }
+  }
+
+  protected static int getDefaultMonitorWidth() {
+    return (3 * getScreenWidth()) / 4;
+  }
+
+  protected static int getDefaultMonitorHeight() {
+    return (3 * getScreenHeight()) / 4;
+  }
+  //--------------------------------------------------------------------------
+  // Private Methods:
+  //--------------------------------------------------------------------------
+
+
+  //--------------------------------------------------------------------------
+  // Nested Top-Level Classes or Interfaces:
+  //--------------------------------------------------------------------------
+
+}

Propchange: logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/LF5Appender.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/Log4JLogRecord.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/Log4JLogRecord.java?rev=1345524&view=auto
==============================================================================
--- logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/Log4JLogRecord.java (added)
+++ logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/Log4JLogRecord.java Sat Jun  2 15:35:46 2012
@@ -0,0 +1,116 @@
+/*
+ * 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.log4j.lf5;
+
+import org.apache.log4j.spi.ThrowableInformation;
+
+/**
+ * A <code>Log4JLogRecord</code> encapsulates
+ * the details of your log4j <code>LoggingEvent</code> in a format usable
+ * by the <code>LogBrokerMonitor</code>.
+ *
+ * @author Brent Sprecher
+ */
+
+// Contributed by ThoughtWorks Inc.
+
+public class Log4JLogRecord extends LogRecord {
+  //--------------------------------------------------------------------------
+  //   Constants:
+  //--------------------------------------------------------------------------
+
+  //--------------------------------------------------------------------------
+  //   Protected Variables:
+  //--------------------------------------------------------------------------
+
+  //--------------------------------------------------------------------------
+  //   Private Variables:
+  //--------------------------------------------------------------------------
+
+  //--------------------------------------------------------------------------
+  //   Constructors:
+  //--------------------------------------------------------------------------
+
+  /**
+   * Constructs an instance of a <code>Log4JLogRecord</code>.
+   */
+  public Log4JLogRecord() {
+  }
+
+  //--------------------------------------------------------------------------
+  //   Public Methods:
+  //--------------------------------------------------------------------------
+  /**
+   * Determines which <code>Priority</code> levels will
+   * be displayed in colored font when the <code>LogMonitorAppender</code>
+   * renders this log message. By default, messages will be colored
+   * red if they are of <code>Priority</code> ERROR or FATAL.
+   *
+   * @return true if the log level is ERROR or FATAL.
+   */
+  public boolean isSevereLevel() {
+    boolean isSevere = false;
+
+    if (LogLevel.ERROR.equals(getLevel()) ||
+        LogLevel.FATAL.equals(getLevel())) {
+      isSevere = true;
+    }
+
+    return isSevere;
+  }
+
+  /**
+   * Set stack trace information associated with this Log4JLogRecord.
+   * When this method is called, the stack trace in a
+   * String-based format is made
+   * available via the getThrownStackTrace() method.
+   *
+   * @param throwableInfo An org.apache.log4j.spi.ThrowableInformation to
+   * associate with this Log4JLogRecord.
+   * @see #getThrownStackTrace()
+   */
+  public void setThrownStackTrace(ThrowableInformation throwableInfo) {
+    String[] stackTraceArray = throwableInfo.getThrowableStrRep();
+
+    StringBuffer stackTrace = new StringBuffer();
+    String nextLine;
+
+    for (int i = 0; i < stackTraceArray.length; i++) {
+      nextLine = stackTraceArray[i] + "\n";
+      stackTrace.append(nextLine);
+    }
+
+    _thrownStackTrace = stackTrace.toString();
+  }
+
+  //--------------------------------------------------------------------------
+  //   Protected Methods:
+  //--------------------------------------------------------------------------
+
+  //--------------------------------------------------------------------------
+  //   Private Methods:
+  //--------------------------------------------------------------------------
+
+  //--------------------------------------------------------------------------
+  //   Nested Top-Level Classes or Interfaces:
+  //--------------------------------------------------------------------------
+
+}
+
+
+

Propchange: logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/Log4JLogRecord.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/LogLevel.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/LogLevel.java?rev=1345524&view=auto
==============================================================================
--- logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/LogLevel.java (added)
+++ logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/LogLevel.java Sat Jun  2 15:35:46 2012
@@ -0,0 +1,278 @@
+/*
+ * 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.log4j.lf5;
+
+import java.awt.Color;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * The LogLevel class defines a set of standard logging levels.
+ *
+ * The logging Level objects are ordered and are specified by ordered
+ * integers. Enabling logging at a given level also enables logging at all
+ * higher levels.
+ *
+ * @author Michael J. Sikorsky
+ * @author Robert Shaw
+ * @author Brent Sprecher
+ * @author Richard Hurst
+ * @author Brad Marlborough
+ */
+
+// Contributed by ThoughtWorks Inc.
+
+public class LogLevel implements java.io.Serializable {
+  //--------------------------------------------------------------------------
+  //   Constants:
+  //--------------------------------------------------------------------------
+
+  // log4j log levels.
+  public final static LogLevel FATAL = new LogLevel("FATAL", 0);
+  public final static LogLevel ERROR = new LogLevel("ERROR", 1);
+  public final static LogLevel WARN = new LogLevel("WARN", 2);
+  public final static LogLevel INFO = new LogLevel("INFO", 3);
+  public final static LogLevel DEBUG = new LogLevel("DEBUG", 4);
+
+  // jdk1.4 log levels NOTE: also includes INFO
+  public final static LogLevel SEVERE = new LogLevel("SEVERE", 1);
+  public final static LogLevel WARNING = new LogLevel("WARNING", 2);
+  public final static LogLevel CONFIG = new LogLevel("CONFIG", 4);
+  public final static LogLevel FINE = new LogLevel("FINE", 5);
+  public final static LogLevel FINER = new LogLevel("FINER", 6);
+  public final static LogLevel FINEST = new LogLevel("FINEST", 7);
+
+  //--------------------------------------------------------------------------
+  //   Protected Variables:
+  //--------------------------------------------------------------------------
+  protected String _label;
+  protected int _precedence;
+  //--------------------------------------------------------------------------
+  //   Private Variables:
+  //--------------------------------------------------------------------------
+  private static LogLevel[] _log4JLevels;
+  private static LogLevel[] _jdk14Levels;
+  private static LogLevel[] _allDefaultLevels;
+  private static Map _logLevelMap;
+  private static Map _logLevelColorMap;
+  private static Map _registeredLogLevelMap = new HashMap();
+
+  //--------------------------------------------------------------------------
+  //   Constructors:
+  //--------------------------------------------------------------------------
+  static {
+    _log4JLevels = new LogLevel[]{FATAL, ERROR, WARN, INFO, DEBUG};
+    _jdk14Levels = new LogLevel[]{SEVERE, WARNING, INFO,
+                                  CONFIG, FINE, FINER, FINEST};
+    _allDefaultLevels = new LogLevel[]{FATAL, ERROR, WARN, INFO, DEBUG,
+                                       SEVERE, WARNING, CONFIG, FINE, FINER, FINEST};
+
+    _logLevelMap = new HashMap();
+    for (int i = 0; i < _allDefaultLevels.length; i++) {
+      _logLevelMap.put(_allDefaultLevels[i].getLabel(), _allDefaultLevels[i]);
+    }
+
+    // prepopulate map with levels and text color of black
+    _logLevelColorMap = new HashMap();
+    for (int i = 0; i < _allDefaultLevels.length; i++) {
+      _logLevelColorMap.put(_allDefaultLevels[i], Color.black);
+    }
+  }
+
+  public LogLevel(String label, int precedence) {
+    _label = label;
+    _precedence = precedence;
+  }
+
+  //--------------------------------------------------------------------------
+  //   Public Methods:
+  //--------------------------------------------------------------------------
+
+  /**
+   * Return the Label of the LogLevel.
+   */
+  public String getLabel() {
+    return _label;
+  }
+
+  /**
+   * Returns true if the level supplied is encompassed by this level.
+   * For example, LogLevel.SEVERE encompasses no other LogLevels and
+   * LogLevel.FINE encompasses all other LogLevels.  By definition,
+   * a LogLevel encompasses itself.
+   */
+  public boolean encompasses(LogLevel level) {
+    if (level.getPrecedence() <= getPrecedence()) {
+      return true;
+    }
+
+    return false;
+  }
+
+  /**
+   * Convert a log level label into a LogLevel object.
+   *
+   * @param level The label of a level to be converted into a LogLevel.
+   * @return LogLevel The LogLevel with a label equal to level.
+   * @throws LogLevelFormatException Is thrown when the level can not be
+   *         converted into a LogLevel.
+   */
+  public static LogLevel valueOf(String level)
+      throws LogLevelFormatException {
+    LogLevel logLevel = null;
+    if (level != null) {
+      level = level.trim().toUpperCase();
+      logLevel = (LogLevel) _logLevelMap.get(level);
+    }
+
+    // Didn't match, Check for registered LogLevels
+    if (logLevel == null && _registeredLogLevelMap.size() > 0) {
+      logLevel = (LogLevel) _registeredLogLevelMap.get(level);
+    }
+
+    if (logLevel == null) {
+      StringBuffer buf = new StringBuffer();
+      buf.append("Error while trying to parse (" + level + ") into");
+      buf.append(" a LogLevel.");
+      throw new LogLevelFormatException(buf.toString());
+    }
+    return logLevel;
+  }
+
+  /**
+   * Registers a used defined LogLevel.
+   *
+   * @param logLevel The log level to be registered. Cannot be a default LogLevel
+   * @return LogLevel The replaced log level.
+   */
+  public static LogLevel register(LogLevel logLevel) {
+    if (logLevel == null) return null;
+
+    // ensure that this is not a default log level
+    if (_logLevelMap.get(logLevel.getLabel()) == null) {
+      return (LogLevel) _registeredLogLevelMap.put(logLevel.getLabel(), logLevel);
+    }
+
+    return null;
+  }
+
+  public static void register(LogLevel[] logLevels) {
+    if (logLevels != null) {
+      for (int i = 0; i < logLevels.length; i++) {
+        register(logLevels[i]);
+      }
+    }
+  }
+
+  public static void register(List logLevels) {
+    if (logLevels != null) {
+      Iterator it = logLevels.iterator();
+      while (it.hasNext()) {
+        register((LogLevel) it.next());
+      }
+    }
+  }
+
+  public boolean equals(Object o) {
+    boolean equals = false;
+
+    if (o instanceof LogLevel) {
+      if (this.getPrecedence() ==
+          ((LogLevel) o).getPrecedence()) {
+        equals = true;
+      }
+
+    }
+
+    return equals;
+  }
+
+  public int hashCode() {
+    return _label.hashCode();
+  }
+
+  public String toString() {
+    return _label;
+  }
+
+  // set a text color for a specific log level
+  public void setLogLevelColorMap(LogLevel level, Color color) {
+    // remove the old entry
+    _logLevelColorMap.remove(level);
+    // add the new color entry
+    if (color == null) {
+      color = Color.black;
+    }
+    _logLevelColorMap.put(level, color);
+  }
+
+  public static void resetLogLevelColorMap() {
+    // empty the map
+    _logLevelColorMap.clear();
+
+    // repopulate map and reset text color black
+    for (int i = 0; i < _allDefaultLevels.length; i++) {
+      _logLevelColorMap.put(_allDefaultLevels[i], Color.black);
+    }
+  }
+
+  /**
+   * @return A <code>List</code> of <code>LogLevel</code> objects that map
+   * to log4j <code>Priority</code> objects.
+   */
+  public static List getLog4JLevels() {
+    return Arrays.asList(_log4JLevels);
+  }
+
+  public static List getJdk14Levels() {
+    return Arrays.asList(_jdk14Levels);
+  }
+
+  public static List getAllDefaultLevels() {
+    return Arrays.asList(_allDefaultLevels);
+  }
+
+  public static Map getLogLevelColorMap() {
+    return _logLevelColorMap;
+  }
+
+  //--------------------------------------------------------------------------
+  //   Protected Methods:
+  //--------------------------------------------------------------------------
+
+  protected int getPrecedence() {
+    return _precedence;
+  }
+
+  //--------------------------------------------------------------------------
+  //   Private Methods:
+  //--------------------------------------------------------------------------
+
+  //--------------------------------------------------------------------------
+  //   Nested Top-Level Classes or Interfaces:
+  //--------------------------------------------------------------------------
+
+}
+
+
+
+
+
+

Propchange: logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/LogLevel.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/LogLevelFormatException.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/LogLevelFormatException.java?rev=1345524&view=auto
==============================================================================
--- logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/LogLevelFormatException.java (added)
+++ logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/LogLevelFormatException.java Sat Jun  2 15:35:46 2012
@@ -0,0 +1,73 @@
+/*
+ * 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.log4j.lf5;
+
+/**
+ * Thrown to indicate that the client has attempted to convert a string
+ * to one the LogLevel types, but the string does not have the appropriate
+ * format.
+ *
+ * @author Michael J. Sikorsky<
+ * @author Robert Shaw
+ */
+
+// Contributed by ThoughtWorks Inc.
+
+public class LogLevelFormatException extends Exception {
+  //--------------------------------------------------------------------------
+  //   Constants:
+  //--------------------------------------------------------------------------
+
+  //--------------------------------------------------------------------------
+  //   Protected Variables:
+  //--------------------------------------------------------------------------
+
+  //--------------------------------------------------------------------------
+  //   Private Variables:
+  //--------------------------------------------------------------------------
+
+  //--------------------------------------------------------------------------
+  //   Constructors:
+  //--------------------------------------------------------------------------
+
+  public LogLevelFormatException(String message) {
+    super(message);
+  }
+
+  //--------------------------------------------------------------------------
+  //   Public Methods:
+  //--------------------------------------------------------------------------
+
+  //--------------------------------------------------------------------------
+  //   Protected Methods:
+  //--------------------------------------------------------------------------
+
+  //--------------------------------------------------------------------------
+  //   Private Methods:
+  //--------------------------------------------------------------------------
+
+  //--------------------------------------------------------------------------
+  //   Nested Top-Level Classes or Interfaces:
+  //--------------------------------------------------------------------------
+
+}
+
+
+
+
+
+

Propchange: logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/LogLevelFormatException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/LogRecord.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/LogRecord.java?rev=1345524&view=auto
==============================================================================
--- logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/LogRecord.java (added)
+++ logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/LogRecord.java Sat Jun  2 15:35:46 2012
@@ -0,0 +1,395 @@
+/*
+ * 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.log4j.lf5;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+/**
+ * LogRecord.  A LogRecord encapsulates the details of your desired log
+ * request.
+ *
+ * @author Michael J. Sikorsky
+ * @author Robert Shaw
+ */
+
+// Contributed by ThoughtWorks Inc.
+
+public abstract class LogRecord implements java.io.Serializable {
+  //--------------------------------------------------------------------------
+  //   Constants:
+  //--------------------------------------------------------------------------
+
+  //--------------------------------------------------------------------------
+  //   Protected Variables:
+  //--------------------------------------------------------------------------
+  protected static long _seqCount = 0;
+
+  protected LogLevel _level;
+  protected String _message;
+  protected long _sequenceNumber;
+  protected long _millis;
+  protected String _category;
+  protected String _thread;
+  protected String _thrownStackTrace;
+  protected Throwable _thrown;
+  protected String _ndc;
+  protected String _location;
+
+  //--------------------------------------------------------------------------
+  //   Private Variables:
+  //--------------------------------------------------------------------------
+
+  //--------------------------------------------------------------------------
+  //   Constructors:
+  //--------------------------------------------------------------------------
+
+  public LogRecord() {
+    super();
+
+    _millis = System.currentTimeMillis();
+    _category = "Debug";
+    _message = "";
+    _level = LogLevel.INFO;
+    _sequenceNumber = getNextId();
+    _thread = Thread.currentThread().toString();
+    _ndc = "";
+    _location = "";
+  }
+
+  //--------------------------------------------------------------------------
+  //   Public Methods:
+  //--------------------------------------------------------------------------
+
+  /**
+   * Get the level of this LogRecord.
+   *
+   * @return The LogLevel of this record.
+   * @see #setLevel(LogLevel)
+   * @see LogLevel
+   */
+  public LogLevel getLevel() {
+    return (_level);
+  }
+
+  /**
+   * Set the level of this LogRecord.
+   *
+   * @param level The LogLevel for this record.
+   * @see #getLevel()
+   * @see LogLevel
+   */
+  public void setLevel(LogLevel level) {
+    _level = level;
+  }
+
+  /**
+   * Abstract method. Must be overridden to indicate what log level
+   * to show in red.
+   */
+  public abstract boolean isSevereLevel();
+
+  /**
+   * @return true if getThrown().toString() is a non-empty string.
+   */
+  public boolean hasThrown() {
+    Throwable thrown = getThrown();
+    if (thrown == null) {
+      return false;
+    }
+    String thrownString = thrown.toString();
+    return thrownString != null && thrownString.trim().length() != 0;
+  }
+
+  /**
+   * @return true if isSevereLevel() or hasThrown() returns true.
+   */
+  public boolean isFatal() {
+    return isSevereLevel() || hasThrown();
+  }
+
+  /**
+   * Get the category asscociated with this LogRecord.  For a more detailed
+   * description of what a category is see setCategory().
+   *
+   * @return The category of this record.
+   * @see #setCategory(String)
+   */
+  public String getCategory() {
+    return (_category);
+  }
+
+  /**
+   * Set the category associated with this LogRecord. A category represents
+   * a hierarchical dot (".") separated namespace for messages.
+   * The definition of a category is application specific, but a common convention
+   * is as follows:
+   *
+   * <p>
+   * When logging messages
+   * for a particluar class you can use its class name:
+   * com.thoughtworks.framework.servlet.ServletServiceBroker.<br><br>
+   * Futhermore, to log a message for a particular method in a class
+   * add the method name:
+   * com.thoughtworks.framework.servlet.ServletServiceBroker.init().
+   * </p>
+   *
+   * @param category The category for this record.
+   * @see #getCategory()
+   */
+  public void setCategory(String category) {
+    _category = category;
+  }
+
+  /**
+   * Get the message asscociated with this LogRecord.
+   *
+   * @return The message of this record.
+   * @see #setMessage(String)
+   */
+  public String getMessage() {
+    return (_message);
+  }
+
+  /**
+   * Set the message associated with this LogRecord.
+   *
+   * @param message The message for this record.
+   * @see #getMessage()
+   */
+  public void setMessage(String message) {
+    _message = message;
+  }
+
+  /**
+   * Get the sequence number associated with this LogRecord.  Sequence numbers
+   * are generally assigned when a LogRecord is constructed.  Sequence numbers
+   * start at 0 and increase with each newly constructed LogRocord.
+   *
+   * @return The sequence number of this record.
+   * @see #setSequenceNumber(long)
+   */
+  public long getSequenceNumber() {
+    return (_sequenceNumber);
+  }
+
+  /**
+   * Set the sequence number assocsiated with this LogRecord.  A sequence number
+   * will automatically be assigned to evey newly constructed LogRecord, however,
+   * this method can override the value.
+   *
+   * @param number The sequence number.
+   * @see #getSequenceNumber()
+   */
+  public void setSequenceNumber(long number) {
+    _sequenceNumber = number;
+  }
+
+  /**
+   * Get the event time of this record in milliseconds from 1970.
+   * When a LogRecord is constructed the event time is set but may be
+   * overridden by calling setMillis();
+   *
+   * @return The event time of this record in milliseconds from 1970.
+   * @see #setMillis(long)
+   */
+  public long getMillis() {
+    return _millis;
+  }
+
+  /**
+   * Set the event time of this record.  When a LogRecord is constructed
+   * the event time is set but may be overridden by calling this method.
+   *
+   * @param millis The time in milliseconds from 1970.
+   * @see #getMillis()
+   */
+  public void setMillis(long millis) {
+    _millis = millis;
+  }
+
+  /**
+   * Get the thread description asscociated with this LogRecord.  When a
+   * LogRecord is constructed, the thread description is set by calling:
+   * Thread.currentThread().toString().  You may supply a thread description
+   * of your own by calling the setThreadDescription(String) method.
+   *
+   * @return The thread description of this record.
+   * @see #setThreadDescription(String)
+   */
+  public String getThreadDescription() {
+    return (_thread);
+  }
+
+  /**
+   * Set the thread description associated with this LogRecord.  When a
+   * LogRecord is constructed, the thread description is set by calling:
+   * Thread.currentThread().toString().  You may supply a thread description
+   * of your own by calling this method.
+   *
+   * @param threadDescription The description of the thread for this record.
+   * @see #getThreadDescription()
+   */
+  public void setThreadDescription(String threadDescription) {
+    _thread = threadDescription;
+  }
+
+  /**
+   * Get the stack trace in a String-based format for the associated Throwable
+   * of this LogRecord.  The stack trace in a String-based format is set
+   * when the setThrown(Throwable) method is called.
+   *
+   * <p>
+   * Why do we need this method considering that we
+   * have the getThrown() and setThrown() methods?
+   * A Throwable object may not be serializable, however, a String representation
+   * of it is.  Users of LogRecords should generally call this method over
+   * getThrown() for the reasons of serialization.
+   * </p>
+   *
+   * @return The Stack Trace for the asscoiated Throwable of this LogRecord.
+   * @see #setThrown(Throwable)
+   * @see #getThrown()
+   */
+  public String getThrownStackTrace() {
+    return (_thrownStackTrace);
+  }
+
+  /**
+   * Set the ThrownStackTrace for the log record.
+   *
+   * @param trace A String to associate with this LogRecord
+   * @see #getThrownStackTrace()
+   */
+  public void setThrownStackTrace(String trace) {
+    _thrownStackTrace = trace;
+  }
+
+  /**
+   * Get the Throwable associated with this LogRecord.
+   *
+   * @return The LogLevel of this record.
+   * @see #setThrown(Throwable)
+   * @see #getThrownStackTrace()
+   */
+  public Throwable getThrown() {
+    return (_thrown);
+  }
+
+  /**
+   * Set the Throwable associated with this LogRecord.  When this method
+   * is called, the stack trace in a String-based format is made
+   * available via the getThrownStackTrace() method.
+   *
+   * @param thrown A Throwable to associate with this LogRecord.
+   * @see #getThrown()
+   * @see #getThrownStackTrace()
+   */
+  public void setThrown(Throwable thrown) {
+    if (thrown == null) {
+      return;
+    }
+    _thrown = thrown;
+    StringWriter sw = new StringWriter();
+    PrintWriter out = new PrintWriter(sw);
+    thrown.printStackTrace(out);
+    out.flush();
+    _thrownStackTrace = sw.toString();
+    try {
+      out.close();
+      sw.close();
+    } catch (IOException e) {
+      // Do nothing, this should not happen as it is StringWriter.
+    }
+    out = null;
+    sw = null;
+  }
+
+  /**
+   * Return a String representation of this LogRecord.
+   */
+  public String toString() {
+    StringBuffer buf = new StringBuffer();
+    buf.append("LogRecord: [" + _level + ", " + _message + "]");
+    return (buf.toString());
+  }
+
+  /**
+   * Get the NDC (nested diagnostic context) for this record.
+   *
+   * @return The string representing the NDC.
+   */
+  public String getNDC() {
+    return _ndc;
+  }
+
+  /**
+   * Set the NDC (nested diagnostic context) for this record.
+   *
+   * @param ndc A string representing the NDC.
+   */
+  public void setNDC(String ndc) {
+    _ndc = ndc;
+  }
+
+  /**
+   * Get the location in code where this LogRecord originated.
+   *
+   * @return The string containing the location information.
+   */
+  public String getLocation() {
+    return _location;
+  }
+
+  /**
+   * Set the location in code where this LogRecord originated.
+   *
+   * @param location A string containing location information.
+   */
+  public void setLocation(String location) {
+    _location = location;
+  }
+
+  /**
+   * Resets that sequence number to 0.
+   *
+   */
+  public static synchronized void resetSequenceNumber() {
+    _seqCount = 0;
+  }
+
+  //--------------------------------------------------------------------------
+  //   Protected Methods:
+  //--------------------------------------------------------------------------
+
+  protected static synchronized long getNextId() {
+    _seqCount++;
+    return _seqCount;
+  }
+  //--------------------------------------------------------------------------
+  //   Private Methods:
+  //--------------------------------------------------------------------------
+
+  //--------------------------------------------------------------------------
+  //   Nested Top-Level Classes or Interfaces:
+  //--------------------------------------------------------------------------
+
+}
+
+
+

Propchange: logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/LogRecord.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/LogRecordFilter.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/LogRecordFilter.java?rev=1345524&view=auto
==============================================================================
--- logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/LogRecordFilter.java (added)
+++ logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/LogRecordFilter.java Sat Jun  2 15:35:46 2012
@@ -0,0 +1,46 @@
+/*
+ * 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.log4j.lf5;
+
+
+/**
+ * An interface for classes which filters LogRecords.  Implementations
+ * represent a rule or condition which LogRecords may pass or fail.
+ * @see LogRecord
+ *
+ * @author Richard Wan
+ */
+
+// Contributed by ThoughtWorks Inc.
+
+public interface LogRecordFilter {
+  //--------------------------------------------------------------------------
+  //   Constants:
+  //--------------------------------------------------------------------------
+
+  //--------------------------------------------------------------------------
+  //   Public Methods:
+  //--------------------------------------------------------------------------
+
+  /**
+   * @return true if the specified LogRecord satisfies whatever condition
+   * implementing class tests for.
+   */
+  public boolean passes(LogRecord record);
+
+}
+

Propchange: logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/LogRecordFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/PassingLogRecordFilter.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/PassingLogRecordFilter.java?rev=1345524&view=auto
==============================================================================
--- logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/PassingLogRecordFilter.java (added)
+++ logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/PassingLogRecordFilter.java Sat Jun  2 15:35:46 2012
@@ -0,0 +1,74 @@
+/*
+ * 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.log4j.lf5;
+
+
+/**
+ * An implementation of LogRecordFilter which always returns true.
+ *
+ * @author Richard Wan
+ */
+
+// Contributed by ThoughtWorks Inc.
+
+public class PassingLogRecordFilter implements LogRecordFilter {
+  //--------------------------------------------------------------------------
+  //   Constants:
+  //--------------------------------------------------------------------------
+
+  //--------------------------------------------------------------------------
+  //   Protected Variables:
+  //--------------------------------------------------------------------------
+
+  //--------------------------------------------------------------------------
+  //   Private Variables:
+  //--------------------------------------------------------------------------
+
+  //--------------------------------------------------------------------------
+  //   Constructors:
+  //--------------------------------------------------------------------------
+
+  //--------------------------------------------------------------------------
+  //   Public Methods:
+  //--------------------------------------------------------------------------
+
+  /**
+   * @return true;
+   */
+  public boolean passes(LogRecord record) {
+    return true;
+  }
+
+  /**
+   * Does nothing.
+   */
+  public void reset() {
+    // do nothing
+  }
+  //--------------------------------------------------------------------------
+  //   Protected Methods:
+  //--------------------------------------------------------------------------
+
+  //--------------------------------------------------------------------------
+  //   Private Methods:
+  //--------------------------------------------------------------------------
+
+  //--------------------------------------------------------------------------
+  //   Nested Top-Level Classes or Interfaces
+  //--------------------------------------------------------------------------
+}
+

Propchange: logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/PassingLogRecordFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/StartLogFactor5.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/StartLogFactor5.java?rev=1345524&view=auto
==============================================================================
--- logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/StartLogFactor5.java (added)
+++ logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/StartLogFactor5.java Sat Jun  2 15:35:46 2012
@@ -0,0 +1,81 @@
+/*
+ * 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.log4j.lf5;
+
+import org.apache.log4j.lf5.viewer.LogBrokerMonitor;
+
+/**
+ * Starts an instance of the LogFactor5 console for off-line viewing.
+ *
+ * @author Brad Marlborough
+ * @author Richard Hurst
+ */
+
+// Contributed by ThoughtWorks Inc.
+
+public class StartLogFactor5 {
+  //--------------------------------------------------------------------------
+  //   Constants:
+  //--------------------------------------------------------------------------
+
+  //--------------------------------------------------------------------------
+  //   Protected Variables:
+  //--------------------------------------------------------------------------
+
+  //--------------------------------------------------------------------------
+  //   Private Variables:
+  //--------------------------------------------------------------------------
+
+  //--------------------------------------------------------------------------
+  //   Constructors:
+  //--------------------------------------------------------------------------
+
+  //--------------------------------------------------------------------------
+  //   Public Methods:
+  //--------------------------------------------------------------------------
+
+  /**
+   * Main - starts a an instance of the LogFactor5 console and configures
+   * the console settings.
+   */
+  public final static void main(String[] args) {
+
+    LogBrokerMonitor monitor = new LogBrokerMonitor(
+        LogLevel.getLog4JLevels());
+
+    monitor.setFrameSize(LF5Appender.getDefaultMonitorWidth(),
+        LF5Appender.getDefaultMonitorHeight());
+    monitor.setFontSize(12);
+    monitor.show();
+
+  }
+
+  //--------------------------------------------------------------------------
+  //   Protected Methods:
+  //--------------------------------------------------------------------------
+
+  //--------------------------------------------------------------------------
+  //   Private Methods:
+  //--------------------------------------------------------------------------
+
+  //--------------------------------------------------------------------------
+  //   Nested Top-Level Classes or Interfaces
+  //--------------------------------------------------------------------------
+
+}
+
+

Propchange: logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/StartLogFactor5.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/util/AdapterLogRecord.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/util/AdapterLogRecord.java?rev=1345524&view=auto
==============================================================================
--- logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/util/AdapterLogRecord.java (added)
+++ logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/util/AdapterLogRecord.java Sat Jun  2 15:35:46 2012
@@ -0,0 +1,114 @@
+/*
+ * 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.log4j.lf5.util;
+
+import org.apache.log4j.lf5.LogLevel;
+import org.apache.log4j.lf5.LogRecord;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+/**
+ * <p>A LogRecord to be used with the LogMonitorAdapter</p>
+ *
+ * @author Richard Hurst
+ */
+
+// Contributed by ThoughtWorks Inc.
+
+public class AdapterLogRecord extends LogRecord {
+  //--------------------------------------------------------------------------
+  //   Constants:
+  //--------------------------------------------------------------------------
+
+  //--------------------------------------------------------------------------
+  //   Protected Variables:
+  //--------------------------------------------------------------------------
+
+  //--------------------------------------------------------------------------
+  //   Private Variables:
+  //--------------------------------------------------------------------------
+  private static LogLevel severeLevel = null;
+
+  private static StringWriter sw = new StringWriter();
+  private static PrintWriter pw = new PrintWriter(sw);
+
+  //--------------------------------------------------------------------------
+  //   Constructors:
+  //--------------------------------------------------------------------------
+  public AdapterLogRecord() {
+    super();
+  }
+
+  //--------------------------------------------------------------------------
+  //   Public Methods:
+  //--------------------------------------------------------------------------
+  public void setCategory(String category) {
+    super.setCategory(category);
+    super.setLocation(getLocationInfo(category));
+  }
+
+  public boolean isSevereLevel() {
+    if (severeLevel == null) return false;
+    return severeLevel.equals(getLevel());
+  }
+
+  public static void setSevereLevel(LogLevel level) {
+    severeLevel = level;
+  }
+
+  public static LogLevel getSevereLevel() {
+    return severeLevel;
+  }
+
+  //--------------------------------------------------------------------------
+  //   Protected Methods:
+  //--------------------------------------------------------------------------
+  protected String getLocationInfo(String category) {
+    String stackTrace = stackTraceToString(new Throwable());
+    String line = parseLine(stackTrace, category);
+    return line;
+  }
+
+  protected String stackTraceToString(Throwable t) {
+    String s = null;
+
+    synchronized (sw) {
+      t.printStackTrace(pw);
+      s = sw.toString();
+      sw.getBuffer().setLength(0);
+    }
+
+    return s;
+  }
+
+  protected String parseLine(String trace, String category) {
+    int index = trace.indexOf(category);
+    if (index == -1) return null;
+    trace = trace.substring(index);
+    trace = trace.substring(0, trace.indexOf(")") + 1);
+    return trace;
+  }
+  //--------------------------------------------------------------------------
+  //   Private Methods:
+  //--------------------------------------------------------------------------
+
+  //--------------------------------------------------------------------------
+  //   Nested Top-Level Classes or Interfaces
+  //--------------------------------------------------------------------------
+}
+

Propchange: logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/util/AdapterLogRecord.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/util/DateFormatManager.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/util/DateFormatManager.java?rev=1345524&view=auto
==============================================================================
--- logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/util/DateFormatManager.java (added)
+++ logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/util/DateFormatManager.java Sat Jun  2 15:35:46 2012
@@ -0,0 +1,243 @@
+/*
+ * 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.log4j.lf5.util;
+
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
+import java.util.TimeZone;
+
+/**
+ * Date format manager.
+ * Utility class to help manage consistent date formatting and parsing.
+ * It may be advantageous to have multiple DateFormatManagers per
+ * application.  For example, one for handling the output (formatting) of
+ * dates, and another one for handling the input (parsing) of dates.
+ *
+ * @author Robert Shaw
+ * @author Michael J. Sikorsky
+ */
+
+// Contributed by ThoughtWorks Inc.
+public class DateFormatManager {
+  //--------------------------------------------------------------------------
+  //   Constants:
+  //--------------------------------------------------------------------------
+
+  //--------------------------------------------------------------------------
+  //   Protected Variables:
+  //--------------------------------------------------------------------------
+
+  //--------------------------------------------------------------------------
+  //   Private Variables:
+  //--------------------------------------------------------------------------
+  private TimeZone _timeZone = null;
+  private Locale _locale = null;
+
+  private String _pattern = null;
+  private DateFormat _dateFormat = null;
+
+  //--------------------------------------------------------------------------
+  //   Constructors:
+  //--------------------------------------------------------------------------
+  public DateFormatManager() {
+    super();
+    configure();
+  }
+
+  public DateFormatManager(TimeZone timeZone) {
+    super();
+
+    _timeZone = timeZone;
+    configure();
+  }
+
+  public DateFormatManager(Locale locale) {
+    super();
+
+    _locale = locale;
+    configure();
+  }
+
+  public DateFormatManager(String pattern) {
+    super();
+
+    _pattern = pattern;
+    configure();
+  }
+
+  public DateFormatManager(TimeZone timeZone, Locale locale) {
+    super();
+
+    _timeZone = timeZone;
+    _locale = locale;
+    configure();
+  }
+
+  public DateFormatManager(TimeZone timeZone, String pattern) {
+    super();
+
+    _timeZone = timeZone;
+    _pattern = pattern;
+    configure();
+  }
+
+  public DateFormatManager(Locale locale, String pattern) {
+    super();
+
+    _locale = locale;
+    _pattern = pattern;
+    configure();
+  }
+
+  public DateFormatManager(TimeZone timeZone, Locale locale, String pattern) {
+    super();
+
+    _timeZone = timeZone;
+    _locale = locale;
+    _pattern = pattern;
+    configure();
+  }
+
+  //--------------------------------------------------------------------------
+  //   Public Methods:
+  //--------------------------------------------------------------------------
+
+  public synchronized TimeZone getTimeZone() {
+    if (_timeZone == null) {
+      return TimeZone.getDefault();
+    } else {
+      return _timeZone;
+    }
+  }
+
+  public synchronized void setTimeZone(TimeZone timeZone) {
+    _timeZone = timeZone;
+    configure();
+  }
+
+  public synchronized Locale getLocale() {
+    if (_locale == null) {
+      return Locale.getDefault();
+    } else {
+      return _locale;
+    }
+  }
+
+  public synchronized void setLocale(Locale locale) {
+    _locale = locale;
+    configure();
+  }
+
+  public synchronized String getPattern() {
+    return _pattern;
+  }
+
+  /**
+   * Set the pattern. i.e. "EEEEE, MMMMM d, yyyy hh:mm aaa"
+   */
+  public synchronized void setPattern(String pattern) {
+    _pattern = pattern;
+    configure();
+  }
+
+
+  /**
+   * This method has been deprecated in favour of getPattern().
+   * @deprecated Use getPattern().
+   */
+  public synchronized String getOutputFormat() {
+    return _pattern;
+  }
+
+  /**
+   * This method has been deprecated in favour of setPattern().
+   * @deprecated Use setPattern().
+   */
+  public synchronized void setOutputFormat(String pattern) {
+    _pattern = pattern;
+    configure();
+  }
+
+  public synchronized DateFormat getDateFormatInstance() {
+    return _dateFormat;
+  }
+
+  public synchronized void setDateFormatInstance(DateFormat dateFormat) {
+    _dateFormat = dateFormat;
+    // No reconfiguration necessary!
+  }
+
+  public String format(Date date) {
+    return getDateFormatInstance().format(date);
+  }
+
+  public String format(Date date, String pattern) {
+    DateFormat formatter = null;
+    formatter = getDateFormatInstance();
+    if (formatter instanceof SimpleDateFormat) {
+      formatter = (SimpleDateFormat) (formatter.clone());
+      ((SimpleDateFormat) formatter).applyPattern(pattern);
+    }
+    return formatter.format(date);
+  }
+
+  /**
+   * @throws java.text.ParseException
+   */
+  public Date parse(String date) throws ParseException {
+    return getDateFormatInstance().parse(date);
+  }
+
+  /**
+   * @throws java.text.ParseException
+   */
+  public Date parse(String date, String pattern) throws ParseException {
+    DateFormat formatter = null;
+    formatter = getDateFormatInstance();
+    if (formatter instanceof SimpleDateFormat) {
+      formatter = (SimpleDateFormat) (formatter.clone());
+      ((SimpleDateFormat) formatter).applyPattern(pattern);
+    }
+    return formatter.parse(date);
+  }
+
+  //--------------------------------------------------------------------------
+  //   Protected Methods:
+  //--------------------------------------------------------------------------
+
+  //--------------------------------------------------------------------------
+  //   Private Methods:
+  //--------------------------------------------------------------------------
+  private synchronized void configure() {
+    _dateFormat = SimpleDateFormat.getDateTimeInstance(DateFormat.FULL,
+        DateFormat.FULL,
+        getLocale());
+    _dateFormat.setTimeZone(getTimeZone());
+
+    if (_pattern != null) {
+      ((SimpleDateFormat) _dateFormat).applyPattern(_pattern);
+    }
+  }
+
+  //--------------------------------------------------------------------------
+  //   Nested Top-Level Classes or Interfaces:
+  //--------------------------------------------------------------------------
+
+}

Propchange: logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/util/DateFormatManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/util/LogFileParser.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/util/LogFileParser.java?rev=1345524&view=auto
==============================================================================
--- logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/util/LogFileParser.java (added)
+++ logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/util/LogFileParser.java Sat Jun  2 15:35:46 2012
@@ -0,0 +1,301 @@
+/*
+ * 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.log4j.lf5.util;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import javax.swing.SwingUtilities;
+
+import org.apache.log4j.lf5.Log4JLogRecord;
+import org.apache.log4j.lf5.LogLevel;
+import org.apache.log4j.lf5.LogLevelFormatException;
+import org.apache.log4j.lf5.LogRecord;
+import org.apache.log4j.lf5.viewer.LogBrokerMonitor;
+import org.apache.log4j.lf5.viewer.LogFactor5ErrorDialog;
+import org.apache.log4j.lf5.viewer.LogFactor5LoadingDialog;
+
+/**
+ * Provides utility methods for input and output streams.
+ *
+ * @author Brad Marlborough
+ * @author Richard Hurst
+ */
+
+// Contributed by ThoughtWorks Inc.
+
+public class LogFileParser implements Runnable {
+  //--------------------------------------------------------------------------
+  //   Constants:
+  //--------------------------------------------------------------------------
+  public static final String RECORD_DELIMITER = "[slf5s.start]";
+  public static final String ATTRIBUTE_DELIMITER = "[slf5s.";
+  public static final String DATE_DELIMITER = ATTRIBUTE_DELIMITER + "DATE]";
+  public static final String THREAD_DELIMITER = ATTRIBUTE_DELIMITER + "THREAD]";
+  public static final String CATEGORY_DELIMITER = ATTRIBUTE_DELIMITER + "CATEGORY]";
+  public static final String LOCATION_DELIMITER = ATTRIBUTE_DELIMITER + "LOCATION]";
+  public static final String MESSAGE_DELIMITER = ATTRIBUTE_DELIMITER + "MESSAGE]";
+  public static final String PRIORITY_DELIMITER = ATTRIBUTE_DELIMITER + "PRIORITY]";
+  public static final String NDC_DELIMITER = ATTRIBUTE_DELIMITER + "NDC]";
+
+  //--------------------------------------------------------------------------
+  //   Protected Variables:
+  //--------------------------------------------------------------------------
+
+  //--------------------------------------------------------------------------
+  //   Private Variables:
+  //--------------------------------------------------------------------------
+  private static SimpleDateFormat _sdf = new SimpleDateFormat("dd MMM yyyy HH:mm:ss,S");
+  private LogBrokerMonitor _monitor;
+  LogFactor5LoadingDialog _loadDialog;
+  private InputStream _in = null;
+
+  //--------------------------------------------------------------------------
+  //   Constructors:
+  //--------------------------------------------------------------------------
+  public LogFileParser(File file) throws IOException,
+      FileNotFoundException {
+    this(new FileInputStream(file));
+  }
+
+  public LogFileParser(InputStream stream) throws IOException {
+    _in = stream;
+  }
+  //--------------------------------------------------------------------------
+  //   Public Methods:
+  //--------------------------------------------------------------------------
+
+  /**
+   * Starts a new thread to parse the log file and create a LogRecord.
+   * See run().
+   * @param monitor LogBrokerMonitor
+   */
+  public void parse(LogBrokerMonitor monitor) throws RuntimeException {
+    _monitor = monitor;
+    Thread t = new Thread(this);
+    t.start();
+  }
+
+  /**
+   * Parses the file and creates new log records and adds the record
+   * to the monitor.
+   */
+  public void run() {
+
+    int index = 0;
+    int counter = 0;
+    LogRecord temp;
+    boolean isLogFile = false;
+
+    _loadDialog = new LogFactor5LoadingDialog(
+        _monitor.getBaseFrame(), "Loading file...");
+
+
+    try {
+      String logRecords = loadLogFile(_in);
+
+      while ((counter = logRecords.indexOf(RECORD_DELIMITER, index)) != -1) {
+        temp = createLogRecord(logRecords.substring(index, counter));
+        isLogFile = true;
+
+        if (temp != null) {
+          _monitor.addMessage(temp);
+        }
+
+        index = counter + RECORD_DELIMITER.length();
+      }
+
+      if (index < logRecords.length() && isLogFile) {
+        temp = createLogRecord(logRecords.substring(index));
+
+        if (temp != null) {
+          _monitor.addMessage(temp);
+        }
+      }
+
+      if (isLogFile == false) {
+        throw new RuntimeException("Invalid log file format");
+      }
+      SwingUtilities.invokeLater(new Runnable() {
+        public void run() {
+          destroyDialog();
+        }
+      });
+
+    } catch (RuntimeException e) {
+      destroyDialog();
+      displayError("Error - Invalid log file format.\nPlease see documentation"
+          + " on how to load log files.");
+    } catch (IOException e) {
+      destroyDialog();
+      displayError("Error - Unable to load log file!");
+    }
+
+    _in = null;
+  }
+
+  //--------------------------------------------------------------------------
+  //   Protected Methods:
+  //--------------------------------------------------------------------------
+  protected void displayError(String message) {
+    LogFactor5ErrorDialog error = new LogFactor5ErrorDialog(
+        _monitor.getBaseFrame(), message);
+
+  }
+
+  //--------------------------------------------------------------------------
+  //   Private Methods:
+  //--------------------------------------------------------------------------
+  private void destroyDialog() {
+    _loadDialog.hide();
+    _loadDialog.dispose();
+  }
+
+  /**
+   * Loads a log file from a web server into the LogFactor5 GUI.
+   */
+  private String loadLogFile(InputStream stream) throws IOException {
+    BufferedInputStream br = new BufferedInputStream(stream);
+
+    int count = 0;
+    int size = br.available();
+
+    StringBuffer sb = null;
+    if (size > 0) {
+      sb = new StringBuffer(size);
+    } else {
+      sb = new StringBuffer(1024);
+    }
+
+    while ((count = br.read()) != -1) {
+      sb.append((char) count);
+    }
+
+    br.close();
+    br = null;
+    return sb.toString();
+
+  }
+
+  private String parseAttribute(String name, String record) {
+
+    int index = record.indexOf(name);
+
+    if (index == -1) {
+      return null;
+    }
+
+    return getAttribute(index, record);
+  }
+
+  private long parseDate(String record) {
+    try {
+      String s = parseAttribute(DATE_DELIMITER, record);
+
+      if (s == null) {
+        return 0;
+      }
+
+      Date d = _sdf.parse(s);
+
+      return d.getTime();
+    } catch (ParseException e) {
+      return 0;
+    }
+  }
+
+  private LogLevel parsePriority(String record) {
+    String temp = parseAttribute(PRIORITY_DELIMITER, record);
+
+    if (temp != null) {
+      try {
+        return LogLevel.valueOf(temp);
+      } catch (LogLevelFormatException e) {
+        return LogLevel.DEBUG;
+      }
+
+    }
+
+    return LogLevel.DEBUG;
+  }
+
+  private String parseThread(String record) {
+    return parseAttribute(THREAD_DELIMITER, record);
+  }
+
+  private String parseCategory(String record) {
+    return parseAttribute(CATEGORY_DELIMITER, record);
+  }
+
+  private String parseLocation(String record) {
+    return parseAttribute(LOCATION_DELIMITER, record);
+  }
+
+  private String parseMessage(String record) {
+    return parseAttribute(MESSAGE_DELIMITER, record);
+  }
+
+  private String parseNDC(String record) {
+    return parseAttribute(NDC_DELIMITER, record);
+  }
+
+  private String parseThrowable(String record) {
+    return getAttribute(record.length(), record);
+  }
+
+  private LogRecord createLogRecord(String record) {
+    if (record == null || record.trim().length() == 0) {
+      return null;
+    }
+
+    LogRecord lr = new Log4JLogRecord();
+    lr.setMillis(parseDate(record));
+    lr.setLevel(parsePriority(record));
+    lr.setCategory(parseCategory(record));
+    lr.setLocation(parseLocation(record));
+    lr.setThreadDescription(parseThread(record));
+    lr.setNDC(parseNDC(record));
+    lr.setMessage(parseMessage(record));
+    lr.setThrownStackTrace(parseThrowable(record));
+
+    return lr;
+  }
+
+
+  private String getAttribute(int index, String record) {
+    int start = record.lastIndexOf(ATTRIBUTE_DELIMITER, index - 1);
+
+    if (start == -1) {
+      return record.substring(0, index);
+    }
+
+    start = record.indexOf("]", start);
+
+    return record.substring(start + 1, index).trim();
+  }
+  //--------------------------------------------------------------------------
+  //   Nested Top-Level Classes or Interfaces
+  //--------------------------------------------------------------------------
+
+}

Propchange: logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/util/LogFileParser.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/util/LogMonitorAdapter.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/util/LogMonitorAdapter.java?rev=1345524&view=auto
==============================================================================
--- logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/util/LogMonitorAdapter.java (added)
+++ logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/util/LogMonitorAdapter.java Sat Jun  2 15:35:46 2012
@@ -0,0 +1,289 @@
+/*
+ * 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.log4j.lf5.util;
+
+import java.awt.Toolkit;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.log4j.lf5.LogLevel;
+import org.apache.log4j.lf5.LogRecord;
+import org.apache.log4j.lf5.viewer.LogBrokerMonitor;
+
+/**
+ * <p>LogMonitorAdapter facilitates the usage of the LogMonitor</p>
+ *
+ * @author Richard Hurst
+ */
+
+// Contributed by ThoughtWorks Inc.
+
+public class LogMonitorAdapter {
+  //--------------------------------------------------------------------------
+  //   Constants:
+  //--------------------------------------------------------------------------
+  public static final int LOG4J_LOG_LEVELS = 0;
+  public static final int JDK14_LOG_LEVELS = 1;
+  //--------------------------------------------------------------------------
+  //   Protected Variables:
+  //--------------------------------------------------------------------------
+
+  //--------------------------------------------------------------------------
+  //   Private Variables:
+  //--------------------------------------------------------------------------
+  private LogBrokerMonitor _logMonitor;
+  private LogLevel _defaultLevel = null;
+
+  //--------------------------------------------------------------------------
+  //   Constructors:
+  //--------------------------------------------------------------------------
+  private LogMonitorAdapter(List userDefinedLevels) {
+    super();
+    // set the default level to be the first entry in the list
+    _defaultLevel = (LogLevel) userDefinedLevels.get(0);
+    _logMonitor = new LogBrokerMonitor(userDefinedLevels);
+
+    _logMonitor.setFrameSize(getDefaultMonitorWidth(),
+        getDefaultMonitorHeight());
+    _logMonitor.setFontSize(12);
+    _logMonitor.show();
+  }
+  //--------------------------------------------------------------------------
+  //   Public Methods:
+  //--------------------------------------------------------------------------
+  /**
+   * <p>Creates an instance of LogMonitorAdapter using the
+   * log levels inticated by the parameter. Log4J and JDK1.4 both have default
+   * LogLevels which are set but these levels can be overriden.<p>
+   *
+   * @param loglevels An integer representing either Log4J or JDK1.4 logging levels
+   * @return LogMonitorAdapter
+   */
+  public static LogMonitorAdapter newInstance(int loglevels) {
+    LogMonitorAdapter adapter;
+    if (loglevels == JDK14_LOG_LEVELS) {
+      adapter = newInstance(LogLevel.getJdk14Levels());
+      adapter.setDefaultLevel(LogLevel.FINEST);
+      adapter.setSevereLevel(LogLevel.SEVERE);
+    } else {
+      adapter = newInstance(LogLevel.getLog4JLevels());
+      adapter.setDefaultLevel(LogLevel.DEBUG);
+      adapter.setSevereLevel(LogLevel.FATAL);
+    }
+    return adapter;
+  }
+
+  /**
+   * <p>Creates an instance of LogMonitorAdapter using the specified LogLevels.
+   * The first LogLevel in the array is used as the default LogLevel unless
+   * changed using the setDefaultLevel method.<p>
+   *
+   * @param userDefined An array of user defined LogLevel objects.
+   * @return LogMonitorAdapter
+   */
+  public static LogMonitorAdapter newInstance(LogLevel[] userDefined) {
+    if (userDefined == null) {
+      return null;
+    }
+    return newInstance(Arrays.asList(userDefined));
+  }
+
+  /**
+   * <p>Creates an instance of LogMonitorAdapter using the specified LogLevels.
+   * The first LogLevel in the List is used as the default LogLevel unless
+   * changed using the setDefaultLevel method.<p>
+   *
+   * @param userDefinedLevels A list of user defined LogLevel objects.
+   * @return LogMonitorAdapter
+   */
+  public static LogMonitorAdapter newInstance(List userDefinedLevels) {
+    return new LogMonitorAdapter(userDefinedLevels);
+  }
+
+  /**
+   * <p>Adds a LogRecord to the LogMonitor.<p>
+   *
+   * @param record The LogRecord object to be logged in the logging monitor.
+   */
+  public void addMessage(LogRecord record) {
+    _logMonitor.addMessage(record);
+  }
+
+  /**
+   * <p>Set the maximum number of records to be displayed in the monitor<p>
+   *
+   * @param maxNumberOfRecords
+   */
+  public void setMaxNumberOfRecords(int maxNumberOfRecords) {
+    _logMonitor.setMaxNumberOfLogRecords(maxNumberOfRecords);
+  }
+
+  /**
+   * <p>Set the default log level to be used when logging messages without
+   * specifying a LogLevel.<p>
+   *
+   * @param level
+   */
+  public void setDefaultLevel(LogLevel level) {
+    _defaultLevel = level;
+  }
+
+  /**
+   * <p>Gets the default LogLevel for the Adapter.<p>
+   *
+   * @return LogLevel
+   */
+  public LogLevel getDefaultLevel() {
+    return _defaultLevel;
+  }
+
+  /**
+   * <p>Sets the Severe LogLevel.</p>
+   *
+   * @param level
+   */
+  public void setSevereLevel(LogLevel level) {
+    AdapterLogRecord.setSevereLevel(level);
+  }
+
+  /**
+   * <p>Gets the current Severe LogLevel <p>
+   *
+   * @return LogLevel
+   */
+  public LogLevel getSevereLevel() {
+    return AdapterLogRecord.getSevereLevel();
+  }
+
+  /**
+   * <p>Log a complete message to the Monitor.<p>
+   *
+   * @param category The category to be used
+   * @param level The log level to apply to the message
+   * @param message The message
+   * @param t The throwable content of the message
+   * @param NDC The NDC really only applies to Log4J and the parameter can
+   *            usually be ignored.
+   */
+  public void log(String category, LogLevel level, String message,
+      Throwable t, String NDC) {
+    AdapterLogRecord record = new AdapterLogRecord();
+    record.setCategory(category);
+    record.setMessage(message);
+    record.setNDC(NDC);
+    record.setThrown(t);
+
+    if (level == null) {
+      record.setLevel(getDefaultLevel());
+    } else {
+      record.setLevel(level);
+    }
+
+    addMessage(record);
+  }
+
+  /**
+   * <p>Log a message to the Monitor and use the default LogLevel.<p>
+   *
+   * @param category The category to be used
+   * @param message The message
+   */
+  public void log(String category, String message) {
+    log(category, null, message);
+  }
+
+  /**
+   * <p>Log a message to the Monitor.<p>
+   *
+   * @param category The category to be used
+   * @param level The log level to apply to the message
+   * @param message The message
+   * @param NDC
+   */
+  public void log(String category, LogLevel level, String message, String NDC) {
+    log(category, level, message, null, NDC);
+  }
+
+  /**
+   * <p>Log a message to the Monitor.<p>
+   *
+   * @param category The category to be used
+   * @param level The log level to apply to the message
+   * @param message The message
+   * @param t The throwable content of the message
+   */
+  public void log(String category, LogLevel level, String message,
+      Throwable t) {
+    log(category, level, message, t, null);
+  }
+
+  /**
+   * <p>Log a message to the Monitor.<p>
+   *
+   * @param category The category to be used
+   * @param level The log level to apply to the message
+   * @param message The message
+   */
+  public void log(String category, LogLevel level, String message) {
+    log(category, level, message, null, null);
+  }
+
+  //--------------------------------------------------------------------------
+  //   Protected Methods:
+  //--------------------------------------------------------------------------
+  /**
+   * @return the screen width from Toolkit.getScreenSize()
+   * if possible, otherwise returns 800
+   * @see java.awt.Toolkit
+   */
+  protected static int getScreenWidth() {
+    try {
+      return Toolkit.getDefaultToolkit().getScreenSize().width;
+    } catch (Throwable t) {
+      return 800;
+    }
+  }
+
+  /**
+   * @return the screen height from Toolkit.getScreenSize()
+   * if possible, otherwise returns 600
+   * @see java.awt.Toolkit
+   */
+  protected static int getScreenHeight() {
+    try {
+      return Toolkit.getDefaultToolkit().getScreenSize().height;
+    } catch (Throwable t) {
+      return 600;
+    }
+  }
+
+  protected static int getDefaultMonitorWidth() {
+    return (3 * getScreenWidth()) / 4;
+  }
+
+  protected static int getDefaultMonitorHeight() {
+    return (3 * getScreenHeight()) / 4;
+  }
+  //--------------------------------------------------------------------------
+  //   Private Methods:
+  //--------------------------------------------------------------------------
+
+  //--------------------------------------------------------------------------
+  //   Nested Top-Level Classes or Interfaces
+  //--------------------------------------------------------------------------
+}
+

Propchange: logging/log4j/branches/log4j12-bz53299/modules/lf5/src/main/java/org/apache/log4j/lf5/util/LogMonitorAdapter.java
------------------------------------------------------------------------------
    svn:eol-style = native