[Checkins] SVN: zc.resumelb/trunk/src/zc/resumelb/ Changed the way the zkresumelb (load-balancer program that works with
jim
cvs-admin at zope.org
Wed Mar 28 18:34:49 UTC 2012
Log message for revision 124777:
Changed the way the zkresumelb (load-balancer program that works with
ZooKeeper) handles access logs. Now, you pass a Python logging logger
name. If you don't pass anything, then nothing will be logged.
Changed:
U zc.resumelb/trunk/src/zc/resumelb/README.txt
U zc.resumelb/trunk/src/zc/resumelb/zk.py
U zc.resumelb/trunk/src/zc/resumelb/zk.test
-=-
Modified: zc.resumelb/trunk/src/zc/resumelb/README.txt
===================================================================
--- zc.resumelb/trunk/src/zc/resumelb/README.txt 2012-03-28 15:02:14 UTC (rev 124776)
+++ zc.resumelb/trunk/src/zc/resumelb/README.txt 2012-03-28 18:34:45 UTC (rev 124777)
@@ -242,6 +242,13 @@
Change History
==============
+0.3.0 (2012-03-28)
+------------------
+
+Change the way the zkresumelb (load-balancer program that works with
+ZooKeeper) handles access logs. Now, you pass a Python logging package
+logger name. If you don't pass anything, then nothing will be logged.
+
0.2.0 (2012-03-27)
------------------
Modified: zc.resumelb/trunk/src/zc/resumelb/zk.py
===================================================================
--- zc.resumelb/trunk/src/zc/resumelb/zk.py 2012-03-28 15:02:14 UTC (rev 124776)
+++ zc.resumelb/trunk/src/zc/resumelb/zk.py 2012-03-28 18:34:45 UTC (rev 124777)
@@ -95,12 +95,8 @@
'-a', '--address', default=':0',
help="Address to listed on for web requests"
)
+ parser.add_option('-l', '--access-logger', help='Access-log logger name.')
parser.add_option(
- '-l', '--access-log', default='-',
- help='Access-log path.\n\n'
- 'Use - (default) for standard output.\n'
- )
- parser.add_option(
'-b', '--backlog', type='int',
help="Server backlog setting.")
parser.add_option(
@@ -196,9 +192,10 @@
else:
spawn = 'default'
- accesslog = options.access_log
- if isinstance(accesslog, str):
- accesslog = sys.stdout if accesslog == '-' else open(accesslog, 'a')
+ if options.access_logger:
+ accesslog = AccessLog(options.access_logger)
+ else:
+ accesslog = None
server = gevent.pywsgi.WSGIServer(
addr, lb.handle_wsgi, backlog = options.backlog,
@@ -256,4 +253,9 @@
zk.close()
else:
gevent.sleep(.01)
- return lb, server, accesslog
+ return lb, server
+
+class AccessLog:
+
+ def __init__(self, logger):
+ self.write = logging.getLogger(logger).info
Modified: zc.resumelb/trunk/src/zc/resumelb/zk.test
===================================================================
--- zc.resumelb/trunk/src/zc/resumelb/zk.test 2012-03-28 15:02:14 UTC (rev 124776)
+++ zc.resumelb/trunk/src/zc/resumelb/zk.test 2012-03-28 18:34:45 UTC (rev 124777)
@@ -184,9 +184,8 @@
-h, --help show this help message and exit
-a ADDRESS, --address=ADDRESS
Address to listed on for web requests
- -l ACCESS_LOG, --access-log=ACCESS_LOG
- Access-log path. Use - (default) for
- standard output.
+ -l ACCESS_LOGGER, --access-logger=ACCESS_LOGGER
+ Access-log logger name.
-b BACKLOG, --backlog=BACKLOG
Server backlog setting.
-d, --backdoor Run a backdoor server. Use with caution!
@@ -215,15 +214,11 @@
>>> gevent.signal.reset_mock()
- >>> lb, server, accesslog = zc.resumelb.zk.lbmain(
+ >>> lb, server = zc.resumelb.zk.lbmain(
... 'zookeeper.example.com:2181 /test/lb -s :0')
>>> sig, sighandler = gevent.signal.call_args[0]
- >>> import sys
- >>> accesslog is sys.stdout
- True
-
At this point, the lb is running and listening on all interfaces using
a self assigned port.
@@ -256,7 +251,6 @@
... ''')
>>> print sock.recv(9999) # doctest: +ELLIPSIS
- 127.0.0.1 - - [2012-01-28 15:29:30] "GET /hi.html HTTP/1.0" 200 226 0.002349
HTTP/1.0 200 OK...
If we create another worker, it will be seen by the load
@@ -340,9 +334,9 @@
... f.write("oops")
>>> with mock.patch('ZConfig.configureLoggers') as configureLoggers:
- ... lb, server, accesslog = zc.resumelb.zk.lbmain(
+ ... lb, server = zc.resumelb.zk.lbmain(
... 'zookeeper.example.com:2181 /test/lb'
- ... ' -alocalhost:0 -laccess.log -b1 -m1'
+ ... ' -alocalhost:0 -laccess -b1 -m1'
... ' --logger-configuration log.conf '
... ' -rzc.resumelb.tests:test_classifier -eoops.html'
... )
@@ -370,6 +364,12 @@
The 3rd collection failed because we said to only accept one
connection at a time and set the backlog to 1.
+We specified a logger name for the access log. Let's set up a log
+handler, so we can verify that accesses were logged there.
+
+ >>> import zope.testing.loggingsupport
+ >>> accesslog = zope.testing.loggingsupport.InstalledHandler('access')
+
Let's do a request.
>>> sock.sendall('''GET /hi.html HTTP/1.0\r
@@ -383,14 +383,16 @@
>>> sock.close()
>>> sock2.close()
-We didn't get an access log entry in the output, because it's in the
-access log.
+We now have access-log records in the access-log handler:
- >>> accesslog.flush()
- >>> with open('access.log') as f:
- ... print f.read(),
- 127.0.0.1 - - [2012-01-29 14:11:37] "GET /hi.html HTTP/1.0" 200 226 0.001074
+ >>> print accesslog # doctest: +NORMALIZE_WHITESPACE
+ access INFO
+ 127.0.0.1 - -
+ [2012-03-28 13:57:58] "GET /hi.html HTTP/1.0" 200 226 0.034563
+
+ >>> accesslog.uninstall()
+
By looking at the lb's pool's skilled data structure, we can see that
the test request classifier was used.
@@ -433,14 +435,11 @@
... zookeeper='zookeeper.example.com:2181', path='/test/lb/workers',
... address='127.0.0.1:0')
- >>> import StringIO
- >>> accesslog = StringIO.StringIO()
-
>>> with mock.patch('ZConfig.configureLoggers') as configureLoggers:
... with mock.patch('logging.basicConfig') as basicConfig:
... lb_greenlet = gevent.spawn(zc.resumelb.zk.lbmain, [
... '-a127.0.0.1:0', '--logger-configuration', 'INFO',
- ... '-l', accesslog, 'zookeeper.example.com:2181', '/test/lb'])
+ ... 'zookeeper.example.com:2181', '/test/lb'])
... gevent.sleep(.1)
... if configureLoggers.called: print 'configureLoggers'
... basicConfig.assert_called_with(level=20)
@@ -456,9 +455,6 @@
>>> print sock.recv(9999) # doctest: +ELLIPSIS
HTTP/1.0 200 OK...
- >>> print accesslog.getvalue(),
- 127.0.0.1 - - [2012-01-31 07:46:31] "GET /hi.html HTTP/1.0" 200 226 0.001165
-
>>> server.stop()
>>> lb.stop()
@@ -468,7 +464,7 @@
... with mock.patch('logging.basicConfig') as basicConfig:
... lb_greenlet = gevent.spawn(zc.resumelb.zk.lbmain, [
... '-a127.0.0.1:0', '--logger-configuration', '42',
- ... '-l', accesslog, 'zookeeper.example.com:2181', '/test/lb'])
+ ... 'zookeeper.example.com:2181', '/test/lb'])
... gevent.sleep(.1)
... if configureLoggers.called: print 'configureLoggers'
... basicConfig.assert_called_with(level=42)
More information about the checkins
mailing list