You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by cr...@apache.org on 2003/01/23 10:08:45 UTC

cvs commit: jakarta-avalon-logkit/src/java/org/apache/log/output/lf5 LF5LogTarget.java LogKitLogRecord.java package.html

crafterm    2003/01/23 01:08:45

  Modified:    .        build.xml
  Added:       src/java/org/apache/log/output/lf5 LF5LogTarget.java
                        LogKitLogRecord.java package.html
  Log:
  Applied LogFactor5 patch.
  
  Submitted by: Sylvain Wallez <sy...@anyware-tech.com>
  
  Revision  Changes    Path
  1.85      +4 -2      jakarta-avalon-logkit/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-logkit/build.xml,v
  retrieving revision 1.84
  retrieving revision 1.85
  diff -u -r1.84 -r1.85
  --- build.xml	12 Dec 2002 17:37:51 -0000	1.84
  +++ build.xml	23 Jan 2003 09:08:44 -0000	1.85
  @@ -162,8 +162,8 @@
     <target name="import-log4j-jar" description="Imports the Log4J API if required">
   
   
  -    <get src="http://www.ibiblio.org/maven/log4j/jars/log4j-1.1.3.jar"
  -        dest="${lib.dir}/log4j-1.1.3.jar"
  +    <get src="http://www.ibiblio.org/maven/log4j/jars/log4j-1.2.7.jar"
  +        dest="${lib.dir}/log4j-1.2.7.jar"
           verbose="true"
           usetimestamp="true"/>
           
  @@ -306,6 +306,8 @@
                  unless="javax.jms.present"/>
         <exclude name="org/apache/log/output/test/DBTargetTestCase.java"
                  unless="javax.sql.present"/>
  +      <exclude name="org/apache/log/output/lf5/**"
  +               unless="log4j.present"/>
       </javac>
   
       <copy todir="${build.classes}">
  
  
  
  1.1                  jakarta-avalon-logkit/src/java/org/apache/log/output/lf5/LF5LogTarget.java
  
  Index: LF5LogTarget.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.log.output.lf5;
  
  import org.apache.log.*;
  import org.apache.log.format.Formatter;
  import org.apache.log.format.PatternFormatter;
  
  import org.apache.log4j.lf5.viewer.LogBrokerMonitor;
  
  /**
   * A {@link LogTarget} that displays log events using the
   * <a href="http://jakarta.apache.org/log4j/docs/lf5/overview.html">LogFactor5</a>
   * Swing GUI.
   *
   * @author <a href="sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Revision: 1.1 $ $Date: 2003/01/23 09:08:45 $
   */
  public class LF5LogTarget implements LogTarget
  {
      /** Common monitor */
      static private LogBrokerMonitor c_defaultLogMonitor;
      
      /** Default context map formatter */
      static private Formatter        c_defaultContextFormatter = new PatternFormatter("");
      
      /** Monitor for this LogTarget */
      private LogBrokerMonitor        m_monitor;
      
      /** Format for context maps */
      private Formatter               m_contextFormatter = c_defaultContextFormatter;
      
      /**
       * Create a <code>LogFactorLogTarget</code> on a given <code>LogBrokerMonitor</code>.
       */
      public LF5LogTarget( final LogBrokerMonitor monitor )
      {
          m_monitor = monitor;
      }
      
      /**
       * Create <code>LogFactorLogTarget</code> on the default <code>LogBrokerMonitor</code>.
       */
      public LF5LogTarget()
      {
          // Creation of m_monitor is deferred up to the first call to processEvent().
          // This allows the Swing window to pop up only if this target is actually used.
      }
      
      /**
       * Sets the {@link Formatter} that will be used to produce the "NDC" (nested diagnostic
       * context) text on the GUI.
       */
      public void setNDCFormatter( Formatter formatter )
      {
      	m_contextFormatter = formatter;
      }
      
      /**
       * Get the default <code>LogBrokerMonitor</code> instance.
       */
      public synchronized static LogBrokerMonitor getDefaultMonitor()
      {
          if( null == c_defaultLogMonitor )
          {
              c_defaultLogMonitor = new LogBrokerMonitor( LogKitLogRecord.LOGKIT_LOGLEVELS );
              c_defaultLogMonitor.setFontSize( 12 );
              c_defaultLogMonitor.show();
          }
          
          return c_defaultLogMonitor;
      }        
      
      /**
       * Process a log event.
       */
      public void processEvent( final LogEvent event )
      {
          if ( null == m_monitor )
          {
              m_monitor = getDefaultMonitor();
          }
  
          m_monitor.addMessage( new LogKitLogRecord( event, m_contextFormatter ) );
      }
  }
  
  
  1.1                  jakarta-avalon-logkit/src/java/org/apache/log/output/lf5/LogKitLogRecord.java
  
  Index: LogKitLogRecord.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.log.output.lf5;
  
  import org.apache.log.*;
  import org.apache.log.format.Formatter;
  import org.apache.log.util.StackIntrospector;
  
  import java.util.Arrays;
  import java.util.List;
  
  import org.apache.log4j.lf5.LogRecord;
  import org.apache.log4j.lf5.LogLevel;
  
  /**
   * An implementation of a LogFactor5 <code>LogRecord</code> based on a
   * LogKit {@link LogEvent}.
   *
   * @author <a href="sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Revision: 1.1 $ $Date: 2003/01/23 09:08:45 $
   */
  
  public class LogKitLogRecord extends LogRecord
  {
      /** Is this a severe event ? */
      private boolean m_severe;
  
      /**
       * Create a LogFactor record from a LogKit event
       */
      public LogKitLogRecord( final LogEvent event, final Formatter fmt )
      {
          final ContextMap contextMap = event.getContextMap();
  
          Object contextObject;
  
          // Category
          this.setCategory( event.getCategory() );
  
          // Level
          this.setLevel( toLogLevel( event.getPriority() ) );
          m_severe = event.getPriority().isGreater( Priority.INFO );
  
          // Location
          if ( null != contextMap && null != ( contextObject = contextMap.get( "method" ) ) )
          {
              this.setLocation( contextObject.toString() );
          }
          else
          {
              this.setLocation( StackIntrospector.getCallerMethod( Logger.class ) );
          }
  
          // Message
          this.setMessage( event.getMessage() );
  
          // Millis
          this.setMillis( event.getTime() );
  
          // NDC
          this.setNDC( fmt.format(event) );
  
          // SequenceNumber
          //this.setSequenceNumber( 0L );
  
          // ThreadDescription
          if( null != contextMap && null != ( contextObject = contextMap.get( "thread" ) ) )
          {
              this.setThreadDescription( contextObject.toString() );
          }
          else
          {
              this.setThreadDescription( Thread.currentThread().getName() );
          }
  
          // Thrown
          this.setThrown( event.getThrowable() );
  
          // ThrownStackTrace
          //this.setThrownStackTrace("");
      }
  
      public boolean isSevereLevel()
      {
          return m_severe;
      }
  
      /**
       * Convert a LogKit <code>Priority</code> to a LogFactor <code>LogLevel</code>.
       */
      public LogLevel toLogLevel( final Priority priority )
      {
          if ( Priority.DEBUG == priority )
              return LogLevel.DEBUG;
          else if ( Priority.INFO == priority )
              return LogLevel.INFO;
          else if ( Priority.WARN == priority )
              return LogLevel.WARN;
          else if ( Priority.ERROR == priority )
              return LogLevel.ERROR;
          else if ( Priority.FATAL_ERROR == priority )
              return LogLevel.FATAL;
          else
              return new LogLevel( priority.getName(), priority.getValue() );
      }
  
      /**
       * The <code>LogLevel</code>s corresponding to LogKit priorities.
       */
      public final static List LOGKIT_LOGLEVELS =
          Arrays.asList(new LogLevel[] {
              LogLevel.FATAL, LogLevel.ERROR, LogLevel.WARN, LogLevel.INFO, LogLevel.DEBUG
          });
  }
  
  
  1.1                  jakarta-avalon-logkit/src/java/org/apache/log/output/lf5/package.html
  
  Index: package.html
  ===================================================================
  <html><body>
  LogFactor5 (Swing GUI) based LogTarget. For more info about LogFactor5, please consult its
  <a href="http://jakarta.apache.org/log4j/docs/lf5/overview.html">documentation</a>.
  </body></html>
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>