[Checkins] SVN: zope.app.wsgi/branches/achapman_username_logging/ - enhanced the ILoggingInfo feature test using an adapter stub

Roger Ineichen roger at projekt01.ch
Thu Apr 2 21:09:50 EDT 2009


Log message for revision 98798:
  - enhanced the ILoggingInfo feature test using an adapter stub
  - added change note
  

Changed:
  U   zope.app.wsgi/branches/achapman_username_logging/CHANGES.txt
  U   zope.app.wsgi/branches/achapman_username_logging/src/zope/app/wsgi/README.txt

-=-
Modified: zope.app.wsgi/branches/achapman_username_logging/CHANGES.txt
===================================================================
--- zope.app.wsgi/branches/achapman_username_logging/CHANGES.txt	2009-04-02 21:28:31 UTC (rev 98797)
+++ zope.app.wsgi/branches/achapman_username_logging/CHANGES.txt	2009-04-03 01:09:49 UTC (rev 98798)
@@ -5,7 +5,11 @@
 3.5.2 (unreleased)
 ------------------
 
-- ...
+- 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/branches/achapman_username_logging/src/zope/app/wsgi/README.txt
===================================================================
--- zope.app.wsgi/branches/achapman_username_logging/src/zope/app/wsgi/README.txt	2009-04-02 21:28:31 UTC (rev 98797)
+++ zope.app.wsgi/branches/achapman_username_logging/src/zope/app/wsgi/README.txt	2009-04-03 01:09:49 UTC (rev 98798)
@@ -58,12 +58,6 @@
 processed would require us to bring up a lot of Zope 3's system, which would
 be just a little bit too much for this demonstration.
 
-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:
-
-  >>> 'wsgi.logging_info' in environ
-  True
-
 Now that we have seen the manual way of initializing and using the publisher
 application, here is the way it is done using all of Zope 3's setup machinery::
 
@@ -99,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
 ---------------------------
 



More information about the Checkins mailing list