[Checkins] SVN: zope.app.wsgi/trunk/ 'WSGIPublisherApplication' uses now 'ILoggingInfo' adapter to get access log info
Alex Chapman
achapman at zope.com
Fri Apr 3 09:29:15 EDT 2009
Log message for revision 98833:
'WSGIPublisherApplication' uses now 'ILoggingInfo' adapter to get access log info
Changed:
U zope.app.wsgi/trunk/CHANGES.txt
U zope.app.wsgi/trunk/setup.py
U zope.app.wsgi/trunk/src/zope/app/wsgi/README.txt
U zope.app.wsgi/trunk/src/zope/app/wsgi/__init__.py
-=-
Modified: zope.app.wsgi/trunk/CHANGES.txt
===================================================================
--- zope.app.wsgi/trunk/CHANGES.txt 2009-04-03 13:16:17 UTC (rev 98832)
+++ zope.app.wsgi/trunk/CHANGES.txt 2009-04-03 13:29:15 UTC (rev 98833)
@@ -2,11 +2,20 @@
CHANGES
=======
-3.5.2 (unreleased)
+3.5.3 (unreleased)
------------------
- ...
+3.5.2 (2009-04-03)
+------------------
+
+- The ``WSGIPublisherApplication`` uses now the ´´ILoggingInfo´´ concept given
+ from zope.publisher.interfaces.logginginfo for log user infos usable for
+ access logs. This allows you to implement your own access log user info
+ message. See zope.publisher.interfaces.logginginfo.ILoggingInfo for more
+ information.
+
3.5.1 (2009-03-31)
------------------
Modified: zope.app.wsgi/trunk/setup.py
===================================================================
--- zope.app.wsgi/trunk/setup.py 2009-04-03 13:16:17 UTC (rev 98832)
+++ zope.app.wsgi/trunk/setup.py 2009-04-03 13:29:15 UTC (rev 98833)
@@ -18,7 +18,7 @@
from setuptools import setup, find_packages, Extension
setup(name='zope.app.wsgi',
- version = '3.5.2dev',
+ version = '3.5.3dev',
url='http://pypi.python.org/pypi/zope.app.wsgi',
license='ZPL 2.1',
description='WSGI application for the zope.publisher',
Modified: zope.app.wsgi/trunk/src/zope/app/wsgi/README.txt
===================================================================
--- zope.app.wsgi/trunk/src/zope/app/wsgi/README.txt 2009-04-03 13:16:17 UTC (rev 98832)
+++ zope.app.wsgi/trunk/src/zope/app/wsgi/README.txt 2009-04-03 13:29:15 UTC (rev 98833)
@@ -93,6 +93,53 @@
i.e. by calling a method on the server that sets the application.
+Access logging
+--------------
+
+But let's test at least the user info logging feature. We can check the
+environ after being sent to the app and also see that a key has been set to
+store user names for use in access logs.
+
+The key points be default to ``-`` if no user info is found:
+
+ >>> print environ
+ {'wsgi.input': <cStringIO.StringI object at ...>,
+ 'wsgi.logging_info': '-', 'PATH_INFO': '/'}
+
+Since we do not have a principal available in this setup we simply provide
+a ILoggingInfo adapter for our missing principal e.g. None:
+
+ >>> import zope.interface
+ >>> import zope.component
+ >>> from zope.publisher.interfaces.logginginfo import ILoggingInfo
+ >>> from zope.security.interfaces import IPrincipal
+ >>> class LoggingInfoStub(object):
+ ... zope.interface.implements(ILoggingInfo)
+ ... zope.component.adapts(zope.interface.Interface)
+ ... def __init__(self, request):
+ ... self.request = request
+ ... def getLogMessage(self):
+ ... return 'foobar'
+
+Now register the ILoggingInfo adapter and check again:
+
+ >>> zope.component.provideAdapter(LoggingInfoStub)
+ >>> print ''.join(app(environ, start_response))
+ <html><head><title>ComponentLookupError</title></head>
+ <body><h2>ComponentLookupError</h2>
+ A server error occurred.
+ </body></html>
+ <BLANKLINE>
+
+As you can see, the app is still not working but our ILoggingInfo stub get
+invoked and provides a custom logging_info message:
+
+ >>> print environ
+ {'wsgi.input': <cStringIO.StringI object at ...>,
+ 'wsgi.logging_info': 'foobar',
+ 'PATH_INFO': '/'}
+
+
Creating A WSGI Application
---------------------------
Modified: zope.app.wsgi/trunk/src/zope/app/wsgi/__init__.py
===================================================================
--- zope.app.wsgi/trunk/src/zope/app/wsgi/__init__.py 2009-04-03 13:16:17 UTC (rev 98832)
+++ zope.app.wsgi/trunk/src/zope/app/wsgi/__init__.py 2009-04-03 13:29:15 UTC (rev 98833)
@@ -23,6 +23,7 @@
from zope.event import notify
from zope.interface import implements
from zope.publisher.publish import publish
+from zope.publisher.interfaces.logginginfo import ILoggingInfo
from zope.app.appsetup import appsetup
from zope.app.publication.httpfactory import HTTPPublicationRequestFactory
@@ -55,11 +56,13 @@
request = publish(request, handle_errors=handle_errors)
response = request.response
- try:
- environ['wsgi.user_name'] = format_login(
- request.principal.info.login)
- except AttributeError:
- pass
+ # Get logging info from principal for log use
+ logging_info = ILoggingInfo(request.principal, None)
+ if logging_info is None:
+ message = '-'
+ else:
+ message = logging_info.getLogMessage()
+ environ['wsgi.logging_info'] = message
# Start the WSGI server response
start_response(response.getStatusString(), response.getHeaders())
@@ -68,13 +71,6 @@
return response.consumeBodyIter()
-# Defensive against ids with whitespace
-def format_login(login):
- if login != login.replace(' ',''):
- login = '"'+login+'"'
- return login
-
-
class PMDBWSGIPublisherApplication(WSGIPublisherApplication):
def __init__(self, db=None, factory=HTTPPublicationRequestFactory,
More information about the Checkins
mailing list