You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by lg...@apache.org on 2005/04/13 14:07:28 UTC

svn commit: r161175 - cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/log/CocoonLogFormatter.java

Author: lgawron
Date: Wed Apr 13 05:07:26 2005
New Revision: 161175

URL: http://svn.apache.org/viewcvs?view=rev&rev=161175
Log:
Extend CocoonLogFormatter with the ability to log request query string prepended with '?' character.

Modified:
    cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/log/CocoonLogFormatter.java

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/log/CocoonLogFormatter.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/log/CocoonLogFormatter.java?view=diff&r1=161174&r2=161175
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/log/CocoonLogFormatter.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/log/CocoonLogFormatter.java Wed Apr 13 05:07:26 2005
@@ -36,7 +36,8 @@
  *     package name. Warning: This pattern works only if formatting occurs in
  *     the same thread as the call to Logger, i.e. it won't work with
  *     <code>AsyncLogTarget</code>.</li>
- * <li><code>uri</code>: Outputs the request URI.<li>
+ * <li><code>uri</code>: Outputs the request URI.</li>
+ * <li><code>query</code>: Outputs the request query string</li>
  * <li><code>thread</code>: Outputs the name of the current thread (first element
  *     on the context stack).</li>
  * <li><code>host</code>: Outputs the request host header.<li>
@@ -58,11 +59,13 @@
     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 int     TYPE_QUERY  = MAX_TYPE + 5;
 
     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_QUERY_STR       = "query";
     protected final static String  TYPE_THREAD_STR      = "thread";
     protected final static String  TYPE_HOST_STR        = "host";
 
@@ -136,6 +139,8 @@
             return TYPE_THREAD;
         } else if (type.equalsIgnoreCase(TYPE_HOST_STR)) {
             return TYPE_HOST;
+        } else if (type.equalsIgnoreCase(TYPE_QUERY_STR)) {
+            return TYPE_QUERY;  
         } else {
             return super.getTypeIdFor(type);
         }
@@ -153,6 +158,8 @@
                 return getThread(event.getContextMap());
             case TYPE_HOST:
                 return getHost(event.getContextMap());
+            case TYPE_QUERY:
+                return getQueryString(event.getContextMap());
         }
         return super.formatPatternRun(event, run);
     }
@@ -204,6 +211,23 @@
         return "Unknown-URI";
     }
 
+    /**
+     * Find request query string
+     */
+    private String getQueryString(ContextMap ctxMap) {
+        if (ctxMap != null) {
+            final Object context = ctxMap.get("objectModel");
+            if (context != null && context instanceof Map) {
+                // Get the request
+                final Request request = ObjectModelHelper.getRequest((Map) context);
+                if (request != null) {
+                    return "?" + request.getQueryString();
+                }
+            }
+        }
+        return "";
+    }
+    
     /**
      * Find the host header of the request that is being processed.
      */



Re: svn commit: r161175 - cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/log/CocoonLogFormatter.java

Posted by Vadim Gritsenko <va...@reverycodes.com>.
Leszek Gawron wrote:
> Vadim Gritsenko wrote:
> 
>> Leszek Gawron wrote:
>>
>>> Vadim Gritsenko wrote:
>>>
>>>> <format type="cocoon">%5.5{priority} %{time} [%{category}] 
>>>> (%{uri}?%{query}) %{class:short}: %{message}\n</format>
> 
> Can I make that default configuration? If so we should warn users that
> the logged info may contain confidential data.

Dunno... You can add it to the comments though, so at least it is documented.

Vadim

Re: svn commit: r161175 - cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/log/CocoonLogFormatter.java

Posted by Leszek Gawron <lg...@mobilebox.pl>.
Vadim Gritsenko wrote:
> Leszek Gawron wrote:
> 
>> Vadim Gritsenko wrote:
>>
>>> lgawron@apache.org wrote:
>>>
>>>>
>>>> Extend CocoonLogFormatter with the ability to log request query 
>>>> string prepended with '?' character.
>>>
>>>
>>>
>>> Nice! I don't get one thing though: why you are adding '?' in the 
>>> code when you can easily have it in the format string?
>>>
>>> <format type="cocoon">%5.5{priority} %{time} [%{category}] 
>>> (%{uri}?%{query}) %{class:short}: %{message}\n</format>
>>
>>
>> because if you do that:
>>
>> DEBUG   (2005-04-13) 13:07.01:812 [] (Unknown-URI?)
>>                                       ^^^^^^^^^^^^
>>  Unknown-Thread/LoggerSwitch.SwitchingLogger: added logger for category
>>
>> looks a little bit funny :). It's a stupid hack I know.
> 
> 
> Ok :-)
Can I make that default configuration? If so we should warn users that
the logged info may contain confidential data.

-- 
Leszek Gawron                                      lgawron@mobilebox.pl
IT Manager                                         MobileBox sp. z o.o.
+48 (61) 855 06 67                              http://www.mobilebox.pl
mobile: +48 (501) 720 812                       fax: +48 (61) 853 29 65

Re: svn commit: r161175 - cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/log/CocoonLogFormatter.java

Posted by Vadim Gritsenko <va...@reverycodes.com>.
Leszek Gawron wrote:
> Vadim Gritsenko wrote:
> 
>> lgawron@apache.org wrote:
>>
>>>
>>> Extend CocoonLogFormatter with the ability to log request query 
>>> string prepended with '?' character.
>>
>>
>> Nice! I don't get one thing though: why you are adding '?' in the code 
>> when you can easily have it in the format string?
>>
>> <format type="cocoon">%5.5{priority} %{time} [%{category}] 
>> (%{uri}?%{query}) %{class:short}: %{message}\n</format>
> 
> because if you do that:
> 
> DEBUG   (2005-04-13) 13:07.01:812 [] (Unknown-URI?)
>                                       ^^^^^^^^^^^^
>  Unknown-Thread/LoggerSwitch.SwitchingLogger: added logger for category
> 
> looks a little bit funny :). It's a stupid hack I know.

Ok :-)

Vadim

Re: svn commit: r161175 - cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/log/CocoonLogFormatter.java

Posted by Leszek Gawron <lg...@apache.org>.
Vadim Gritsenko wrote:
> lgawron@apache.org wrote:
> 
>>
>> Extend CocoonLogFormatter with the ability to log request query string 
>> prepended with '?' character.
> 
> 
> Nice! I don't get one thing though: why you are adding '?' in the code 
> when you can easily have it in the format string?
> 
> <format type="cocoon">%5.5{priority} %{time} [%{category}] 
> (%{uri}?%{query}) %{class:short}: %{message}\n</format>
> 
> 
> Vadim
because if you do that:

DEBUG   (2005-04-13) 13:07.01:812 [] (Unknown-URI?)
                                       ^^^^^^^^^^^^
  Unknown-Thread/LoggerSwitch.SwitchingLogger: added logger for category

looks a little bit funny :). It's a stupid hack I know.

-- 
Leszek Gawron                                                 MobileBox
lgawron@apache.org                              http://www.mobilebox.pl

Re: svn commit: r161175 - cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/log/CocoonLogFormatter.java

Posted by Vadim Gritsenko <va...@reverycodes.com>.
lgawron@apache.org wrote:
> 
> Extend CocoonLogFormatter with the ability to log request query string prepended with '?' character.

Nice! I don't get one thing though: why you are adding '?' in the code when you 
can easily have it in the format string?

<format type="cocoon">%5.5{priority} %{time} [%{category}] (%{uri}?%{query}) 
%{class:short}: %{message}\n</format>


Vadim