[Zope-Checkins] SVN: Zope/branches/ctheune-extending_error_log/ - Added feature for displaying exception pages as text only. Another feature let's you

Christian Theune ct at gocept.com
Wed Jan 12 12:15:24 EST 2005


Log message for revision 28809:
   - Added feature for displaying exception pages as text only. Another feature let's you
     save this text page as a file in the CLIENT_HOME directory.
  
  

Changed:
  U   Zope/branches/ctheune-extending_error_log/doc/CHANGES.txt
  U   Zope/branches/ctheune-extending_error_log/lib/python/Products/SiteErrorLog/SiteErrorLog.py
  U   Zope/branches/ctheune-extending_error_log/lib/python/Products/SiteErrorLog/tests/testSiteErrorLog.py
  U   Zope/branches/ctheune-extending_error_log/lib/python/Products/SiteErrorLog/www/ok.gif
  U   Zope/branches/ctheune-extending_error_log/lib/python/Products/SiteErrorLog/www/showEntry.pt
  A   Zope/branches/ctheune-extending_error_log/lib/python/Products/SiteErrorLog/www/showEntryText.dtml

-=-
Modified: Zope/branches/ctheune-extending_error_log/doc/CHANGES.txt
===================================================================
--- Zope/branches/ctheune-extending_error_log/doc/CHANGES.txt	2005-01-12 16:39:33 UTC (rev 28808)
+++ Zope/branches/ctheune-extending_error_log/doc/CHANGES.txt	2005-01-12 17:15:23 UTC (rev 28809)
@@ -28,6 +28,10 @@
 
     Features added
 
+      - The SiteErrorLog now supports displaying the exception page as pure
+        text. Additionally you can save individual error log entries as a text
+        file in your CLIENT_HOME (usually INSTANCE_HOME/var) directory.
+
       - FTPServer: a RNFR (rename from) request is now being responded
         with a 550 error code if the source file does not exist
 

Modified: Zope/branches/ctheune-extending_error_log/lib/python/Products/SiteErrorLog/SiteErrorLog.py
===================================================================
--- Zope/branches/ctheune-extending_error_log/lib/python/Products/SiteErrorLog/SiteErrorLog.py	2005-01-12 16:39:33 UTC (rev 28808)
+++ Zope/branches/ctheune-extending_error_log/lib/python/Products/SiteErrorLog/SiteErrorLog.py	2005-01-12 17:15:23 UTC (rev 28809)
@@ -17,6 +17,7 @@
 """
 
 import os
+import os.path
 import sys
 import time
 import logging
@@ -29,7 +30,9 @@
 from AccessControl import ClassSecurityInfo, getSecurityManager, Unauthorized
 from OFS.SimpleItem import SimpleItem
 from Products.PageTemplates.PageTemplateFile import PageTemplateFile
+from Globals import HTMLFile
 from zExceptions.ExceptionFormatter import format_exception
+from App.config import getConfiguration
 
 LOG = logging.getLogger('Zope.SiteErrorLog')
 
@@ -86,6 +89,9 @@
     security.declareProtected(use_error_logging, 'showEntry')
     showEntry = PageTemplateFile('showEntry.pt', _www)
 
+    security.declareProtected(use_error_logging, 'showEntryText')
+    showEntryText = HTMLFile('www/showEntryText', globals())
+
     security.declarePrivate('manage_beforeDelete')
     def manage_beforeDelete(self, item, container):
         if item is self:
@@ -117,9 +123,6 @@
             temp_logs[self._p_oid] = log
         return log
 
-    # Exceptions that happen all the time, so we dont need
-    # to log them. Eventually this should be configured
-    # through-the-web.
     security.declareProtected(use_error_logging, 'forgetEntry')
     def forgetEntry(self, id, REQUEST=None):
         """Removes an entry from the error log."""
@@ -136,6 +139,29 @@
                 message='Error log entry was removed.',
                 action='./manage_main',)
 
+    security.declareProtected(use_error_logging, 'saveEntry')
+    def saveEntry(self, id, REQUEST=None):
+        """Saves an entry in the server's "var" directory."""
+        entry = self.getLogEntryById(id)
+
+        if entry is None:
+            if REQUEST is not None:
+                REQUEST.RESPONSE.redirect(self.absolute_url()+"manage_tabs_message=Exception+not+found.")
+            else:
+                raise KeyError, id
+
+        text = self.showEntryText(self, REQUEST=REQUEST)
+        var = getConfiguration().clienthome
+        filename = os.path.join(var, "Exception-"+id) 
+        f = file(filename, 'wb')
+        f.write(text)
+        f.close()
+        if REQUEST is not None:
+            REQUEST.RESPONSE.redirect(self.absolute_url()+"/showEntry?id=%s&manage_tabs_message=Exception+saved+as+%s+on+server." % (REQUEST.get('id'), filename))
+
+    # Exceptions that happen all the time, so we dont need
+    # to log them. Eventually this should be configured
+    # through-the-web.
     _ignored_exceptions = ( 'Unauthorized', 'NotFound', 'Redirect' )
 
     security.declarePrivate('raising')
@@ -169,6 +195,7 @@
                 username = None
                 userid   = None
                 req_html = None
+                req_text = None
                 try:
                     strv = str(info[1])
                 except:
@@ -182,6 +209,10 @@
                         req_html = str(request)
                     except:
                         pass
+                    try:
+                        req_text = request.text()
+                    except:
+                        pass
                     if strtype == 'NotFound':
                         strv = url
                         next = request['TraversalRequestNameStack']
@@ -203,6 +234,7 @@
                     'userid': userid,
                     'url': url,
                     'req_html': req_html,
+                    'req_text': req_text,
                     })
 
                 cleanup_lock.acquire()

Modified: Zope/branches/ctheune-extending_error_log/lib/python/Products/SiteErrorLog/tests/testSiteErrorLog.py
===================================================================
--- Zope/branches/ctheune-extending_error_log/lib/python/Products/SiteErrorLog/tests/testSiteErrorLog.py	2005-01-12 16:39:33 UTC (rev 28808)
+++ Zope/branches/ctheune-extending_error_log/lib/python/Products/SiteErrorLog/tests/testSiteErrorLog.py	2005-01-12 17:15:23 UTC (rev 28809)
@@ -114,6 +114,22 @@
         # log entries
         self.assertEquals(len(sel_ob.getLogEntries()), previous_log_length)
 
+    def testShowAsText(self):
+        elog = self.app.error_log
+        # Create a predictable error
+        try:
+            raise AttributeError, "DummyAttribute"
+        except AttributeError:
+            info = sys.exc_info()
+            elog.raising(info)
+
+        entry = elog.getLogEntries()[0]['id']
+        self.app.REQUEST.set('id', entry)
+        
+        # Shouldn't raise an Exception and return a string
+        text = elog.showEntryText(elog, REQUEST=self.app.REQUEST)
+        self.assert_(isinstance(text, str))
+
     def testCleanup(self):
         # Need to make sure that the __error_log__ hook gets cleaned up
         self.app._delObject('error_log')

Modified: Zope/branches/ctheune-extending_error_log/lib/python/Products/SiteErrorLog/www/ok.gif
===================================================================
(Binary files differ)

Modified: Zope/branches/ctheune-extending_error_log/lib/python/Products/SiteErrorLog/www/showEntry.pt
===================================================================
--- Zope/branches/ctheune-extending_error_log/lib/python/Products/SiteErrorLog/www/showEntry.pt	2005-01-12 16:39:33 UTC (rev 28808)
+++ Zope/branches/ctheune-extending_error_log/lib/python/Products/SiteErrorLog/www/showEntry.pt	2005-01-12 17:15:23 UTC (rev 28809)
@@ -3,14 +3,19 @@
 
 <h3>Exception traceback</h3>
 
+<div tal:define="entry python:container.getLogEntryById(request.get('id'))">
+
 <p>
-<form action="manage_main" method="GET">
-<input type="submit" name="submit" value=" Return to log " />
+<form tal:attributes="action here/absolute_url" method="GET">
+<input type="hidden" name="id" tal:attributes="value entry/id"/>
+<input type="submit" name="manage_main:action" value=" Return to log " />
+<input type="submit" name="showEntryText:action" value=" Show as text " 
+    tal:condition="entry"/>
+<input type="submit" name="saveEntry:action" value=" Store Exception on Server " 
+    tal:condition="entry"/>
 </form>
 </p>
 
-<div tal:define="entry python:container.getLogEntryById(request.get('id'))">
-
 <em tal:condition="not:entry">
 The specified log entry was not found.  It may have expired.
 </em>

Added: Zope/branches/ctheune-extending_error_log/lib/python/Products/SiteErrorLog/www/showEntryText.dtml
===================================================================
--- Zope/branches/ctheune-extending_error_log/lib/python/Products/SiteErrorLog/www/showEntryText.dtml	2005-01-12 16:39:33 UTC (rev 28808)
+++ Zope/branches/ctheune-extending_error_log/lib/python/Products/SiteErrorLog/www/showEntryText.dtml	2005-01-12 17:15:23 UTC (rev 28809)
@@ -0,0 +1,33 @@
+<dtml-call "REQUEST.RESPONSE.setHeader('content-type', 'text/plain')">Exception Log File
+
+<dtml-let entry="getLogEntryById(REQUEST.get('id'))">
+
+General Information
+-------------------
+
+Time
+  <dtml-var "DateTime(entry['time'])">
+
+User Name (User Id)
+  <dtml-var "entry['username']"> (<dtml-var "entry['userid']">)
+  
+Request URL
+  <dtml-var "entry['url']">
+  
+Exception Type
+  <dtml-var "entry['type']">
+
+Exception Value
+  <dtml-var "entry['value']">
+
+Traceback
+---------
+
+<dtml-var "entry['tb_text']">
+
+REQUEST
+-------
+
+<dtml-var "entry['req_text']"> 
+
+</dtml-let>



More information about the Zope-Checkins mailing list