You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by cz...@apache.org on 2003/08/19 10:43:00 UTC

cvs commit: cocoon-2.1/src/java/org/apache/cocoon/util/log XMLCocoonLogFormatter.java CocoonLogFormatter.java

cziegeler    2003/08/19 01:43:00

  Modified:    .        status.xml
               src/java/org/apache/cocoon/util/log
                        XMLCocoonLogFormatter.java CocoonLogFormatter.java
  Log:
     <action dev="CZ" type="add" fixes-bug="21848" due-to="Unico Hommes" due-to-email="unico@hippo.nl">
       Applying patch for using 'host' in the logging patterns.
     </action>
  
  Revision  Changes    Path
  1.127     +4 -1      cocoon-2.1/status.xml
  
  Index: status.xml
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/status.xml,v
  retrieving revision 1.126
  retrieving revision 1.127
  diff -u -r1.126 -r1.127
  --- status.xml	19 Aug 2003 01:36:30 -0000	1.126
  +++ status.xml	19 Aug 2003 08:43:00 -0000	1.127
  @@ -189,6 +189,9 @@
     <changes>
   
    <release version="@version@" date="@date@">
  +   <action dev="CZ" type="add" fixes-bug="21848" due-to="Unico Hommes" due-to-email="unico@hippo.nl">
  +     Applying patch for using 'host' in the logging patterns.
  +   </action>
      <action dev="JH" type="fix" fixes-bug="22498" due-to="Conal Tuohy" due-to-email="conal@nzetc.org">
        Lucene block: LuceneIndexTransformer configuration fixed.
      </action>
  
  
  
  1.2       +28 -2     cocoon-2.1/src/java/org/apache/cocoon/util/log/XMLCocoonLogFormatter.java
  
  Index: XMLCocoonLogFormatter.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/util/log/XMLCocoonLogFormatter.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XMLCocoonLogFormatter.java	9 Mar 2003 00:09:44 -0000	1.1
  +++ XMLCocoonLogFormatter.java	19 Aug 2003 08:43:00 -0000	1.2
  @@ -88,6 +88,7 @@
    * <li><code>rtime</code> : outputs the relative time (&lt;relative-time&gt;).<li>
    * <li><code>throwable</code> : outputs the exception (&lt;throwable&gt;).<li>
    * <li><code>priority</code> : outputs the priority (&lt;priority&gt;).<li>
  + * <li><code>host</code> : outputs the request host header (&lt;priority&gt;).<li>
    * </ul>
    *
    * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
  @@ -111,6 +112,7 @@
       protected final static int         TYPE_CLASS        = 7;
       protected final static int         TYPE_CLASS_SHORT        = 8;
       protected final static int         TYPE_THREAD        = 9;
  +    protected final static int         TYPE_HOST          = 10;
   
       public final static String[] typeStrings = new String[] {"uri", // 0
            "category",  // 1
  @@ -121,7 +123,8 @@
            "priority",  // 6
            "class",    // 7
            "class:short", // 8
  -         "thread"};  // 9
  +         "thread",   // 9
  +         "host"};   // 10
   
       protected final static String EOL = System.getProperty("line.separator", "\n");
       protected final SimpleDateFormat dateFormatter = new SimpleDateFormat("(yyyy-MM-dd) HH:mm.ss:SSS");
  @@ -215,6 +218,12 @@
                       sb.append(event.getPriority().getName());
                       sb.append("</priority>").append(EOL);
                       break;
  +                
  +                case TYPE_HOST:
  +                    sb.append("<host>");
  +                    sb.append(getHost(event.getContextMap()));
  +                    sb.append("</host>");
  +                    break;
               }
           }
           sb.append("</log-entry>");
  @@ -243,6 +252,23 @@
           return result;
       }
   
  +    private String getHost(ContextMap ctxMap) {
  +        String result = "Unknown-host";
  +        
  +        if (ctxMap != null) {
  +            Object context = ctxMap.get("objectModel");
  +            if (context != null && context instanceof Map) {
  +                // Get the request
  +                Request request = ObjectModelHelper.getRequest((Map)context);
  +                if (request != null) {
  +                    result = request.getHeader("host");
  +                }
  +            }
  +        }
  +        
  +        return result;
  +    }
  +    
       /**
        * Find the request id that is being processed.
        */
  
  
  
  1.2       +29 -1     cocoon-2.1/src/java/org/apache/cocoon/util/log/CocoonLogFormatter.java
  
  Index: CocoonLogFormatter.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/util/log/CocoonLogFormatter.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- CocoonLogFormatter.java	9 Mar 2003 00:09:44 -0000	1.1
  +++ CocoonLogFormatter.java	19 Aug 2003 08:43:00 -0000	1.2
  @@ -87,12 +87,14 @@
       protected final static int     TYPE_CLASS  = MAX_TYPE + 1;
       protected final static int     TYPE_URI    = MAX_TYPE + 2;
       protected final static int     TYPE_THREAD = MAX_TYPE + 3;
  +    protected final static int     TYPE_HOST   = MAX_TYPE + 4;
   
       protected final static String  TYPE_CLASS_STR       = "class";
       protected final static String  TYPE_CLASS_SHORT_STR = "short";
   
       protected final static String  TYPE_URI_STR         = "uri";
       protected final static String  TYPE_THREAD_STR      = "thread";
  +    protected final static String  TYPE_HOST_STR        = "host";
   
       protected final SimpleDateFormat dateFormatter = new SimpleDateFormat("(yyyy-MM-dd) HH:mm.ss:SSS");
   
  @@ -155,6 +157,8 @@
               return TYPE_URI;
           else if (type.equalsIgnoreCase(TYPE_THREAD_STR))
               return TYPE_THREAD;
  +        else if (type.equalsIgnoreCase(TYPE_HOST_STR))
  +            return TYPE_HOST;
           else
               return super.getTypeIdFor( type );
       }
  @@ -172,6 +176,9 @@
   
               case TYPE_THREAD :
                   return getThread(event.getContextMap());
  +            
  +            case TYPE_HOST :
  +                return getHost(event.getContextMap());
           }
   
           return super.formatPatternRun(event, run);
  @@ -223,6 +230,27 @@
                   Request request = ObjectModelHelper.getRequest((Map)context);
                   if (request != null) {
                       result = request.getRequestURI();
  +                }
  +            }
  +        }
  +
  +        return result;
  +    }
  +
  +    /**
  +     * Find the host header of the request that is being processed.
  +     */
  +    private String getHost(ContextMap ctxMap) {
  +        String result = "Unknown-host";
  +
  +        // Get URI from the the object model.
  +        if (ctxMap != null) {
  +            Object context = ctxMap.get("objectModel");
  +            if (context != null && context instanceof Map) {
  +                // Get the request
  +                Request request = ObjectModelHelper.getRequest((Map)context);
  +                if (request != null) {
  +                    result = request.getHeader("host");
                   }
               }
           }