[Zope3-checkins] SVN: Zope3/branches/ZopeX3-3.0/ Changes to access
logging:
Fred L. Drake, Jr.
fred at zope.com
Thu Jun 3 16:38:44 EDT 2004
Log message for revision 25242:
Changes to access logging:
- it's called "access" logging, not "hit" logging
- keep the "hitlog" configuration section, but generate a
DeprecationWarning telling that the "accesslog" section is preferred
Response to checkin message from revision 25133, which introduced <hitlog>:
I wish I'd had time to review the original introduction of <hitlog>
when it went in; it would not be where it is now. The changes to
ZConfig will not be eternalized to the ZConfig project; I'll have to
change things around before the second beta.
Hopefully I'll be able to review zope.server.logger at that point as
well.
-=-
Modified: Zope3/branches/ZopeX3-3.0/src/ZConfig/components/logger/hitlog.xml
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/ZConfig/components/logger/hitlog.xml 2004-06-03 19:47:08 UTC (rev 25241)
+++ Zope3/branches/ZopeX3-3.0/src/ZConfig/components/logger/hitlog.xml 2004-06-03 20:38:44 UTC (rev 25242)
@@ -3,13 +3,29 @@
<import package="ZConfig.components.logger" file="abstract.xml"/>
<import package="ZConfig.components.logger" file="base-logger.xml"/>
+ <abstracttype name="ZConfig.logger.accesslog"/>
+
+ <sectiontype name="accesslog"
+ datatype=".AccessLogFactory"
+ extends="ZConfig.logger.base-logger"
+ implements="ZConfig.logger.accesslog">
+ <description>
+ Configuration for the access logger.
+
+ Note that the setting of verbosity level and message formats are not
+ used.
+ </description>
+ </sectiontype>
+
<sectiontype name="hitlog"
datatype=".HitLogFactory"
extends="ZConfig.logger.base-logger"
- implements="ZConfig.logger.log">
+ implements="ZConfig.logger.accesslog">
<description>
- Configuration for the hit logger.
+ DEPRECATED. Use "accesslog" instead.
+ Configuration for the access logger.
+
Note that the setting of verbosity level and message formats are not
used.
</description>
Modified: Zope3/branches/ZopeX3-3.0/src/ZConfig/components/logger/logger.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/ZConfig/components/logger/logger.py 2004-06-03 19:47:08 UTC (rev 25241)
+++ Zope3/branches/ZopeX3-3.0/src/ZConfig/components/logger/logger.py 2004-06-03 20:38:44 UTC (rev 25242)
@@ -87,10 +87,10 @@
name = None
-class HitLogFactory(LoggerFactoryBase):
- """Logger factory that returns the hit logger."""
+class AccessLogFactory(LoggerFactoryBase):
+ """Logger factory that returns the access logger."""
- name = "hitlog"
+ name = "accesslog"
def create(self):
logger = LoggerFactoryBase.create(self)
@@ -102,6 +102,16 @@
return logger
+class HitLogFactory(AccessLogFactory):
+ """AccessLogFactory that generates a deprecation warning."""
+
+ def create(self):
+ import warnings
+ warnings.warn("<hitlog> is deprecated; use <accesslog> instead",
+ DeprecationWarning)
+ return AccessLogFactory.create(self)
+
+
class LoggerFactory(LoggerFactoryBase):
"""Logger factory that returns the named logger."""
Modified: Zope3/branches/ZopeX3-3.0/src/ZConfig/components/logger/tests/test_logger.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/ZConfig/components/logger/tests/test_logger.py 2004-06-03 19:47:08 UTC (rev 25241)
+++ Zope3/branches/ZopeX3-3.0/src/ZConfig/components/logger/tests/test_logger.py 2004-06-03 20:38:44 UTC (rev 25242)
@@ -226,23 +226,23 @@
return logger
-class TestHitLogging(LoggingTestBase):
+class TestAccessLogging(LoggingTestBase):
- name = "hitlog"
+ name = "accesslog"
_schematext = """
<schema>
<import package='ZConfig.components.logger'/>
- <section type='hitlog' name='*' attribute='hitlog'/>
+ <section type='accesslog' name='*' attribute='accesslog'/>
</schema>
"""
def test_config_without_logger(self):
conf = self.get_config("")
- self.assert_(conf.hitlog is None)
+ self.assert_(conf.accesslog is None)
def test_config_without_handlers(self):
- logger = self.check_simple_logger("<hitlog/>")
+ logger = self.check_simple_logger("<accesslog/>")
# Make sure there's a NullHandler, since a warning gets
# printed if there are no handlers:
self.assertEqual(len(logger.handlers), 1)
@@ -250,13 +250,13 @@
loghandler.NullHandler))
def test_formatter(self):
- logger = self.check_simple_logger("<hitlog>\n"
+ logger = self.check_simple_logger("<accesslog>\n"
" <syslog>\n"
" level error\n"
" facility local3\n"
" format xyzzy\n"
" </syslog>\n"
- "</hitlog>")
+ "</accesslog>")
self.assertEqual(len(logger.handlers), 1)
syslog = logger.handlers[0]
self.assertEqual(syslog.level, logging.ERROR)
@@ -265,11 +265,11 @@
def check_simple_logger(self, text):
conf = self.get_config(text)
- self.assert_(conf.hitlog is not None)
- logger = conf.hitlog()
+ self.assert_(conf.accesslog is not None)
+ logger = conf.accesslog()
self.assert_(isinstance(logger, logging.Logger))
self.assert_(not logger.propagate)
- self.assertEquals(logger.name, "hitlog")
+ self.assertEquals(logger.name, "accesslog")
self.assertEquals(logger.level, logging.INFO)
return logger
@@ -277,7 +277,7 @@
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestConfig))
- suite.addTest(unittest.makeSuite(TestHitLogging))
+ suite.addTest(unittest.makeSuite(TestAccessLogging))
return suite
if __name__ == '__main__':
Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/server/http.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/server/http.py 2004-06-03 19:47:08 UTC (rev 25241)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/server/http.py 2004-06-03 20:38:44 UTC (rev 25242)
@@ -18,16 +18,16 @@
from zope.app.publication.httpfactory import HTTPPublicationRequestFactory
from zope.app.server.servertype import ServerType
-from zope.server.http.commonhitlogger import CommonHitLogger
+from zope.server.http.commonaccesslogger import CommonAccessLogger
from zope.server.http.publisherhttpserver import PMDBHTTPServer
from zope.server.http.publisherhttpserver import PublisherHTTPServer
http = ServerType(PublisherHTTPServer,
HTTPPublicationRequestFactory,
- CommonHitLogger,
+ CommonAccessLogger,
8080, True)
pmhttp = ServerType(PMDBHTTPServer,
HTTPPublicationRequestFactory,
- CommonHitLogger,
+ CommonAccessLogger,
8013, True)
Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/server/main.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/server/main.py 2004-06-03 19:47:08 UTC (rev 25241)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/server/main.py 2004-06-03 20:38:44 UTC (rev 25242)
@@ -84,7 +84,7 @@
sys.setcheckinterval(options.check_interval)
options.eventlog()
- options.hitlog()
+ options.accesslog()
zope.app.appsetup.config(options.site_definition)
Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/server/schema.xml
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/server/schema.xml 2004-06-03 19:47:08 UTC (rev 25241)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/server/schema.xml 2004-06-03 20:38:44 UTC (rev 25242)
@@ -31,9 +31,10 @@
</description>
</section>
- <section type="hitlog" attribute="hitlog" name="*" required="yes">
+ <section type="ZConfig.logger.accesslog" attribute="accesslog" name="*"
+ required="yes">
<description>
- Configuration for the hit log.
+ Configuration for the access log.
</description>
</section>
Copied: Zope3/branches/ZopeX3-3.0/src/zope/server/http/commonaccesslogger.py (from rev 25240, Zope3/branches/ZopeX3-3.0/src/zope/server/http/commonhitlogger.py)
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/server/http/commonhitlogger.py 2004-06-03 19:23:57 UTC (rev 25240)
+++ Zope3/branches/ZopeX3-3.0/src/zope/server/http/commonaccesslogger.py 2004-06-03 20:38:44 UTC (rev 25242)
@@ -0,0 +1,101 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+
+$Id$
+"""
+
+import time
+import sys
+
+from zope.server.http.http_date import monthname
+from zope.server.logger.pythonlogger import PythonLogger
+from zope.server.logger.resolvinglogger import ResolvingLogger
+from zope.server.logger.unresolvinglogger import UnresolvingLogger
+
+class CommonAccessLogger:
+ """Outputs accesses in common HTTP log format.
+ """
+
+ def __init__(self, logger_object=None, resolver=None):
+ if logger_object is None:
+ # logger_object is an IMessageLogger
+ logger_object = PythonLogger('accesslog')
+
+ # self.output is an IRequestLogger
+ if resolver is not None:
+ self.output = ResolvingLogger(resolver, logger_object)
+ else:
+ self.output = UnresolvingLogger(logger_object)
+
+ def compute_timezone_for_log(self, tz):
+ if tz > 0:
+ neg = 1
+ else:
+ neg = 0
+ tz = -tz
+ h, rem = divmod (tz, 3600)
+ m, rem = divmod (rem, 60)
+ if neg:
+ return '-%02d%02d' % (h, m)
+ else:
+ return '+%02d%02d' % (h, m)
+
+ tz_for_log = None
+ tz_for_log_alt = None
+
+ def log_date_string(self, when):
+ logtime = time.localtime(when)
+ Y, M, D, h, m, s = logtime[:6]
+
+ if not time.daylight:
+ tz = self.tz_for_log
+ if tz is None:
+ tz = self.compute_timezone_for_log(time.timezone)
+ self.tz_for_log = tz
+ else:
+ tz = self.tz_for_log_alt
+ if tz is None:
+ tz = self.compute_timezone_for_log(time.altzone)
+ self.tz_for_log_alt = tz
+
+ return '%d/%s/%02d:%02d:%02d:%02d %s' % (
+ D, monthname[M], Y, h, m, s, tz)
+
+
+ def log(self, task):
+ """
+ Receives a completed task and logs it in the
+ common log format.
+ """
+ now = time.time()
+ request_data = task.request_data
+ req_headers = request_data.headers
+
+ user_name = task.auth_user_name or 'anonymous'
+ user_agent = req_headers.get('USER_AGENT', '')
+ referer = req_headers.get('REFERER', '')
+
+ self.output.logRequest(
+ task.channel.addr[0],
+ ' - %s [%s] "%s" %s %d "%s" "%s"\n' % (
+ user_name,
+ self.log_date_string(now),
+ request_data.first_line,
+ task.status,
+ task.bytes_written,
+ referer,
+ user_agent
+ )
+ )
Deleted: Zope3/branches/ZopeX3-3.0/src/zope/server/http/commonhitlogger.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/server/http/commonhitlogger.py 2004-06-03 19:47:08 UTC (rev 25241)
+++ Zope3/branches/ZopeX3-3.0/src/zope/server/http/commonhitlogger.py 2004-06-03 20:38:44 UTC (rev 25242)
@@ -1,101 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""
-
-$Id$
-"""
-
-import time
-import sys
-
-from zope.server.http.http_date import monthname
-from zope.server.logger.pythonlogger import PythonLogger
-from zope.server.logger.resolvinglogger import ResolvingLogger
-from zope.server.logger.unresolvinglogger import UnresolvingLogger
-
-class CommonHitLogger:
- """Outputs hits in common HTTP log format.
- """
-
- def __init__(self, logger_object=None, resolver=None):
- if logger_object is None:
- # logger_object is an IMessageLogger
- logger_object = PythonLogger('hitlog')
-
- # self.output is an IRequestLogger
- if resolver is not None:
- self.output = ResolvingLogger(resolver, logger_object)
- else:
- self.output = UnresolvingLogger(logger_object)
-
- def compute_timezone_for_log(self, tz):
- if tz > 0:
- neg = 1
- else:
- neg = 0
- tz = -tz
- h, rem = divmod (tz, 3600)
- m, rem = divmod (rem, 60)
- if neg:
- return '-%02d%02d' % (h, m)
- else:
- return '+%02d%02d' % (h, m)
-
- tz_for_log = None
- tz_for_log_alt = None
-
- def log_date_string(self, when):
- logtime = time.localtime(when)
- Y, M, D, h, m, s = logtime[:6]
-
- if not time.daylight:
- tz = self.tz_for_log
- if tz is None:
- tz = self.compute_timezone_for_log(time.timezone)
- self.tz_for_log = tz
- else:
- tz = self.tz_for_log_alt
- if tz is None:
- tz = self.compute_timezone_for_log(time.altzone)
- self.tz_for_log_alt = tz
-
- return '%d/%s/%02d:%02d:%02d:%02d %s' % (
- D, monthname[M], Y, h, m, s, tz)
-
-
- def log(self, task):
- """
- Receives a completed task and logs it in the
- common log format.
- """
- now = time.time()
- request_data = task.request_data
- req_headers = request_data.headers
-
- user_name = task.auth_user_name or 'anonymous'
- user_agent = req_headers.get('USER_AGENT', '')
- referer = req_headers.get('REFERER', '')
-
- self.output.logRequest(
- task.channel.addr[0],
- ' - %s [%s] "%s" %s %d "%s" "%s"\n' % (
- user_name,
- self.log_date_string(now),
- request_data.first_line,
- task.status,
- task.bytes_written,
- referer,
- user_agent
- )
- )
Copied: Zope3/branches/ZopeX3-3.0/src/zope/server/http/tests/test_commonaccesslogger.py (from rev 25240, Zope3/branches/ZopeX3-3.0/src/zope/server/http/tests/test_commonhitlogger.py)
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/server/http/tests/test_commonhitlogger.py 2004-06-03 19:23:57 UTC (rev 25240)
+++ Zope3/branches/ZopeX3-3.0/src/zope/server/http/tests/test_commonaccesslogger.py 2004-06-03 20:38:44 UTC (rev 25242)
@@ -0,0 +1,50 @@
+##############################################################################
+#
+# Copyright (c) 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+
+$Id$
+"""
+
+import unittest
+import logging
+
+
+class TestCommonAccessLogger(unittest.TestCase):
+
+ def test_default_constructor(self):
+ from zope.server.http.commonaccesslogger import CommonAccessLogger
+ from zope.server.logger.unresolvinglogger import UnresolvingLogger
+ from zope.server.logger.pythonlogger import PythonLogger
+ logger = CommonAccessLogger()
+ # CommonHitLogger is registered as an argumentless factory via
+ # ZCML, so the defaults should be sensible
+ self.assert_(isinstance(logger.output, UnresolvingLogger))
+ self.assert_(isinstance(logger.output.logger, PythonLogger))
+ self.assert_(logger.output.logger.name, 'accesslog')
+ self.assert_(logger.output.logger.level, logging.INFO)
+
+ # XXX please add unit tests for other methods as well:
+ # compute_timezone_for_log
+ # log_date_string
+ # log
+
+
+def test_suite():
+ suite = unittest.TestSuite()
+ suite.addTest(unittest.makeSuite(TestCommonAccessLogger))
+ return suite
+
+
+if __name__ == '__main__':
+ unittest.main(defaultTest="test_suite")
Deleted: Zope3/branches/ZopeX3-3.0/src/zope/server/http/tests/test_commonhitlogger.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/server/http/tests/test_commonhitlogger.py 2004-06-03 19:47:08 UTC (rev 25241)
+++ Zope3/branches/ZopeX3-3.0/src/zope/server/http/tests/test_commonhitlogger.py 2004-06-03 20:38:44 UTC (rev 25242)
@@ -1,50 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2002 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""
-
-$Id$
-"""
-
-import unittest
-import logging
-
-
-class TestCommonHitLogger(unittest.TestCase):
-
- def test_default_constructor(self):
- from zope.server.http.commonhitlogger import CommonHitLogger
- from zope.server.logger.unresolvinglogger import UnresolvingLogger
- from zope.server.logger.pythonlogger import PythonLogger
- logger = CommonHitLogger()
- # CommonHitLogger is registered as an argumentless factory via
- # ZCML, so the defaults should be sensible
- self.assert_(isinstance(logger.output, UnresolvingLogger))
- self.assert_(isinstance(logger.output.logger, PythonLogger))
- self.assert_(logger.output.logger.name, 'hitlog')
- self.assert_(logger.output.logger.level, logging.INFO)
-
- # XXX please add unit tests for other methods as well:
- # compute_timezone_for_log
- # log_date_string
- # log
-
-
-def test_suite():
- suite = unittest.TestSuite()
- suite.addTest(unittest.makeSuite(TestCommonHitLogger))
- return suite
-
-
-if __name__ == '__main__':
- unittest.main()
Modified: Zope3/branches/ZopeX3-3.0/zope.conf.in
===================================================================
--- Zope3/branches/ZopeX3-3.0/zope.conf.in 2004-06-03 19:47:08 UTC (rev 25241)
+++ Zope3/branches/ZopeX3-3.0/zope.conf.in 2004-06-03 20:38:44 UTC (rev 25242)
@@ -30,7 +30,7 @@
</filestorage>
</zodb>
-<hitlog>
+<accesslog>
# This sets up logging to both a file (access.log) and to standard
# output (STDOUT). The "path" setting can be a relative or absolute
# filesystem path or the tokens STDOUT or STDERR.
@@ -42,7 +42,7 @@
<logfile>
path STDOUT
</logfile>
-</hitlog>
+</accesslog>
<eventlog>
# This sets up logging to both a file (z3.log) and to standard
More information about the Zope3-Checkins
mailing list