[Zope] Re: Zope User in Apache Logs

Josef Meile jmeile at hotmail.com
Wed May 17 05:49:27 EDT 2006


Dear list,

> I've been going through the list archives looking for tips on logging 
> (getting sensible statistics from my log files).
> At the moment I have the setup recommended by most posts, namely 
> multiple Apache virtual hosts that proxies requests to a single Zope 
> instance.
> 
> I would like to know how I can get Apache to log the current Zope user.
> Here's an example from my Apache access_log:
> 10.0.0.100 - - [02/May/2006:15:32:18 +0200] "GET / HTTP/1.1" 200 35721
> 
> Which results in this entry from my Z2.log:
> 127.0.0.1 - adp [02/May/2006:15:32:21 +0200] "GET 
> /VirtualHostBase/http/mysite.com:80/vhosts/mysite.com/VirtualHostRoot/ 
> HTTP/1.1" 200 36054 "" "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; 
> rv:1.8.0.2) Gecko/20060308 Firefox/1.5.0.2"
> 
> The current user is logged by Zope, but not by Apache.
> Is there a way to make Apache aware of who is logged in through Zope?
I'm also trying to do the same thing. I want either to modify the zope
log in order to show the real user IP and replace the referrer by the
one the user typed in the browser (without everything between
VirtualHostBase and VirtualHostRoot) or just return the authenticated
user to apache.

I read the answer from Dieter and unfortunately I'm not authenticating
from Apache. So, I went for the approach indicated by Chris Withers
without any success:

 > If your Zope auth solution can put a header in the http response, 
then > you can use a custom apache logging directive to put this in your
 > Apache log in place of what it thinks the username is.
I put this on the "log" method of the medusa/http_server.py file:
self.response.setHeader('remote_user',name)

and set my apache access log like this:
CustomLog /home/apache/httpd/logs/access_log combined

The combined log is defined as follows:
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" 
combined

There you see the %l and %u directives, which are the "Remote logname" 
and the "Remote user".

But apache still doesn't get the zope authenticated user. So, Chris, do 
you remember what header you set, where, and which method you used?

On the other hand, I also tried to do it the opposite way: modify the 
zope log in order to show the real ip address and remove every 
VirtualHost info from the referrer. I achieved the first part by using 
the following patch:

http://www.zope.org/Collectors/Zope/1732

Then I tried the following in the "log" method of the 
medusa/http_server.py file:

referer=getattr(self,'VIRTUAL_URL_PARTS',None)
#I tried this as well
#referer=getattr(self.request,'VIRTUAL_URL_PARTS',None)
if not referer:
     referer=self.get_header('referer')
     if not referer:
         referer=''
else:
     referer='/' + referer[1]

But it seems that I can't access the 'VIRTUAL_URL_PARTS' key. How can I 
get this information?

Thanks in advanced,
Josef



More information about the Zope mailing list