Commit be8426cf authored by Amos Latteier's avatar Amos Latteier

Added debug logging to the FastCGI Server and fixed hit logging to use common log format.

parent 7150cfcc
...@@ -111,6 +111,8 @@ from ZPublisher.HTTPResponse import HTTPResponse ...@@ -111,6 +111,8 @@ from ZPublisher.HTTPResponse import HTTPResponse
from ZPublisher.HTTPRequest import HTTPRequest from ZPublisher.HTTPRequest import HTTPRequest
from Producers import ShutdownProducer, LoggingProducer, file_part_producer, file_close_producer from Producers import ShutdownProducer, LoggingProducer, file_part_producer, file_close_producer
import DebugLogger
from cStringIO import StringIO from cStringIO import StringIO
from tempfile import TemporaryFile from tempfile import TemporaryFile
import socket, string, os, sys, time import socket, string, os, sys, time
...@@ -425,10 +427,20 @@ class FCGIChannel(asynchat.async_chat): ...@@ -425,10 +427,20 @@ class FCGIChannel(asynchat.async_chat):
elif rec.role == FCGI_RESPONDER: self.remainingRecs = 2 elif rec.role == FCGI_RESPONDER: self.remainingRecs = 2
elif rec.role == FCGI_FILTER: self.remainingRecs = 3 elif rec.role == FCGI_FILTER: self.remainingRecs = 3
# Read some name-value pairs (the CGI environment) # Read some name-value pairs (the CGI environment)
elif rec.recType == FCGI_PARAMS: elif rec.recType == FCGI_PARAMS:
if rec.contentLength == 0: # end of the stream if rec.contentLength == 0: # end of the stream
if self.env.has_key('REQUEST_METHOD'):
method=self.env['REQUEST_METHOD']
else:
method='GET'
if self.env.has_key('PATH_INFO'):
path=self.env['PATH_INFO']
else:
path=''
DebugLogger.log('B', id(self), '%s %s' % (method, path))
self.remainingRecs = self.remainingRecs - 1 self.remainingRecs = self.remainingRecs - 1
self.content_length=string.atoi(self.env.get( self.content_length=string.atoi(self.env.get(
'CONTENT_LENGTH','0')) 'CONTENT_LENGTH','0'))
...@@ -472,6 +484,8 @@ class FCGIChannel(asynchat.async_chat): ...@@ -472,6 +484,8 @@ class FCGIChannel(asynchat.async_chat):
else: else:
# We've got them all. Let ZPublisher do its thang. # We've got them all. Let ZPublisher do its thang.
DebugLogger.log('I', id(self), self.stdin.tell())
# But first, fixup the auth header if using newest mod_fastcgi. # But first, fixup the auth header if using newest mod_fastcgi.
if self.env.has_key('Authorization'): if self.env.has_key('Authorization'):
self.env['HTTP_AUTHORIZATION'] = self.env['Authorization'] self.env['HTTP_AUTHORIZATION'] = self.env['Authorization']
...@@ -494,11 +508,13 @@ class FCGIChannel(asynchat.async_chat): ...@@ -494,11 +508,13 @@ class FCGIChannel(asynchat.async_chat):
def log_request(self, bytes): def log_request(self, bytes):
# XXX need to add reply code logging
DebugLogger.log('E', id(self))
if self.env.has_key('PATH_INFO'): if self.env.has_key('PATH_INFO'):
path='%s%s' % (self.server.module, self.env['PATH_INFO']) path=self.env['PATH_INFO']
else: else:
path='%s/' % self.server.module path=''
if self.env.has_key('REQUEST_METHOD'): if self.env.has_key('REQUEST_METHOD'):
method=self.env['REQUEST_METHOD'] method=self.env['REQUEST_METHOD']
else: else:
...@@ -506,24 +522,24 @@ class FCGIChannel(asynchat.async_chat): ...@@ -506,24 +522,24 @@ class FCGIChannel(asynchat.async_chat):
if self.addr: if self.addr:
self.server.logger.log ( self.server.logger.log (
self.addr[0], self.addr[0],
'%d - - [%s] "%s %s" %d' % ( '%d - - [%s] "%s %s" %d %d' % (
self.addr[1], self.addr[1],
time.strftime ( time.strftime (
'%d/%b/%Y:%H:%M:%S ', '%d/%b/%Y:%H:%M:%S ',
time.gmtime(time.time()) time.gmtime(time.time())
) + tz_for_log, ) + tz_for_log,
method, path, bytes method, path, self.reply_code, bytes
) )
) )
else: else:
self.server.logger.log ( self.server.logger.log (
'127.0.0.1', '127.0.0.1',
'- - [%s] "%s %s" %d' % ( '- - [%s] "%s %s" %d %d' % (
time.strftime ( time.strftime (
'%d/%b/%Y:%H:%M:%S ', '%d/%b/%Y:%H:%M:%S ',
time.gmtime(time.time()) time.gmtime(time.time())
) + tz_for_log, ) + tz_for_log,
method, path, bytes method, path, self.reply_code, bytes
) )
) )
...@@ -636,6 +652,7 @@ class FCGIServer(asyncore.dispatcher): ...@@ -636,6 +652,7 @@ class FCGIServer(asyncore.dispatcher):
logger_object=None): logger_object=None):
self.ip = ip self.ip = ip
self.count=counter()
asyncore.dispatcher.__init__(self) asyncore.dispatcher.__init__(self)
if not logger_object: if not logger_object:
logger_object = logger.file_logger(sys.stdout) logger_object = logger.file_logger(sys.stdout)
...@@ -677,6 +694,7 @@ class FCGIServer(asyncore.dispatcher): ...@@ -677,6 +694,7 @@ class FCGIServer(asyncore.dispatcher):
def handle_accept(self): def handle_accept(self):
self.count.increment()
try: try:
conn, addr = self.accept() conn, addr = self.accept()
except socket.error: except socket.error:
...@@ -743,6 +761,11 @@ class FCGIResponse(HTTPResponse): ...@@ -743,6 +761,11 @@ class FCGIResponse(HTTPResponse):
stdout.write((file_part_producer(t,b,e), l)) stdout.write((file_part_producer(t,b,e), l))
def _finish(self): def _finish(self):
self.channel.reply_code=self.status
DebugLogger.log('A', id(self.channel), '%d %d' % (
self.status, self.stdout.length))
t=self._tempfile t=self._tempfile
if t is not None: if t is not None:
self.stdout.write((file_close_producer(t), 0)) self.stdout.write((file_close_producer(t), 0))
...@@ -791,7 +814,6 @@ class FCGIPipe: ...@@ -791,7 +814,6 @@ class FCGIPipe:
self.recType = recType self.recType = recType
self.length = 0 self.length = 0
def write(self, data): def write(self, data):
if type(data)==type(''): if type(data)==type(''):
datalen = len(data) datalen = len(data)
......
...@@ -111,6 +111,8 @@ from ZPublisher.HTTPResponse import HTTPResponse ...@@ -111,6 +111,8 @@ from ZPublisher.HTTPResponse import HTTPResponse
from ZPublisher.HTTPRequest import HTTPRequest from ZPublisher.HTTPRequest import HTTPRequest
from Producers import ShutdownProducer, LoggingProducer, file_part_producer, file_close_producer from Producers import ShutdownProducer, LoggingProducer, file_part_producer, file_close_producer
import DebugLogger
from cStringIO import StringIO from cStringIO import StringIO
from tempfile import TemporaryFile from tempfile import TemporaryFile
import socket, string, os, sys, time import socket, string, os, sys, time
...@@ -425,10 +427,20 @@ class FCGIChannel(asynchat.async_chat): ...@@ -425,10 +427,20 @@ class FCGIChannel(asynchat.async_chat):
elif rec.role == FCGI_RESPONDER: self.remainingRecs = 2 elif rec.role == FCGI_RESPONDER: self.remainingRecs = 2
elif rec.role == FCGI_FILTER: self.remainingRecs = 3 elif rec.role == FCGI_FILTER: self.remainingRecs = 3
# Read some name-value pairs (the CGI environment) # Read some name-value pairs (the CGI environment)
elif rec.recType == FCGI_PARAMS: elif rec.recType == FCGI_PARAMS:
if rec.contentLength == 0: # end of the stream if rec.contentLength == 0: # end of the stream
if self.env.has_key('REQUEST_METHOD'):
method=self.env['REQUEST_METHOD']
else:
method='GET'
if self.env.has_key('PATH_INFO'):
path=self.env['PATH_INFO']
else:
path=''
DebugLogger.log('B', id(self), '%s %s' % (method, path))
self.remainingRecs = self.remainingRecs - 1 self.remainingRecs = self.remainingRecs - 1
self.content_length=string.atoi(self.env.get( self.content_length=string.atoi(self.env.get(
'CONTENT_LENGTH','0')) 'CONTENT_LENGTH','0'))
...@@ -472,6 +484,8 @@ class FCGIChannel(asynchat.async_chat): ...@@ -472,6 +484,8 @@ class FCGIChannel(asynchat.async_chat):
else: else:
# We've got them all. Let ZPublisher do its thang. # We've got them all. Let ZPublisher do its thang.
DebugLogger.log('I', id(self), self.stdin.tell())
# But first, fixup the auth header if using newest mod_fastcgi. # But first, fixup the auth header if using newest mod_fastcgi.
if self.env.has_key('Authorization'): if self.env.has_key('Authorization'):
self.env['HTTP_AUTHORIZATION'] = self.env['Authorization'] self.env['HTTP_AUTHORIZATION'] = self.env['Authorization']
...@@ -494,11 +508,13 @@ class FCGIChannel(asynchat.async_chat): ...@@ -494,11 +508,13 @@ class FCGIChannel(asynchat.async_chat):
def log_request(self, bytes): def log_request(self, bytes):
# XXX need to add reply code logging
DebugLogger.log('E', id(self))
if self.env.has_key('PATH_INFO'): if self.env.has_key('PATH_INFO'):
path='%s%s' % (self.server.module, self.env['PATH_INFO']) path=self.env['PATH_INFO']
else: else:
path='%s/' % self.server.module path=''
if self.env.has_key('REQUEST_METHOD'): if self.env.has_key('REQUEST_METHOD'):
method=self.env['REQUEST_METHOD'] method=self.env['REQUEST_METHOD']
else: else:
...@@ -506,24 +522,24 @@ class FCGIChannel(asynchat.async_chat): ...@@ -506,24 +522,24 @@ class FCGIChannel(asynchat.async_chat):
if self.addr: if self.addr:
self.server.logger.log ( self.server.logger.log (
self.addr[0], self.addr[0],
'%d - - [%s] "%s %s" %d' % ( '%d - - [%s] "%s %s" %d %d' % (
self.addr[1], self.addr[1],
time.strftime ( time.strftime (
'%d/%b/%Y:%H:%M:%S ', '%d/%b/%Y:%H:%M:%S ',
time.gmtime(time.time()) time.gmtime(time.time())
) + tz_for_log, ) + tz_for_log,
method, path, bytes method, path, self.reply_code, bytes
) )
) )
else: else:
self.server.logger.log ( self.server.logger.log (
'127.0.0.1', '127.0.0.1',
'- - [%s] "%s %s" %d' % ( '- - [%s] "%s %s" %d %d' % (
time.strftime ( time.strftime (
'%d/%b/%Y:%H:%M:%S ', '%d/%b/%Y:%H:%M:%S ',
time.gmtime(time.time()) time.gmtime(time.time())
) + tz_for_log, ) + tz_for_log,
method, path, bytes method, path, self.reply_code, bytes
) )
) )
...@@ -636,6 +652,7 @@ class FCGIServer(asyncore.dispatcher): ...@@ -636,6 +652,7 @@ class FCGIServer(asyncore.dispatcher):
logger_object=None): logger_object=None):
self.ip = ip self.ip = ip
self.count=counter()
asyncore.dispatcher.__init__(self) asyncore.dispatcher.__init__(self)
if not logger_object: if not logger_object:
logger_object = logger.file_logger(sys.stdout) logger_object = logger.file_logger(sys.stdout)
...@@ -677,6 +694,7 @@ class FCGIServer(asyncore.dispatcher): ...@@ -677,6 +694,7 @@ class FCGIServer(asyncore.dispatcher):
def handle_accept(self): def handle_accept(self):
self.count.increment()
try: try:
conn, addr = self.accept() conn, addr = self.accept()
except socket.error: except socket.error:
...@@ -743,6 +761,11 @@ class FCGIResponse(HTTPResponse): ...@@ -743,6 +761,11 @@ class FCGIResponse(HTTPResponse):
stdout.write((file_part_producer(t,b,e), l)) stdout.write((file_part_producer(t,b,e), l))
def _finish(self): def _finish(self):
self.channel.reply_code=self.status
DebugLogger.log('A', id(self.channel), '%d %d' % (
self.status, self.stdout.length))
t=self._tempfile t=self._tempfile
if t is not None: if t is not None:
self.stdout.write((file_close_producer(t), 0)) self.stdout.write((file_close_producer(t), 0))
...@@ -791,7 +814,6 @@ class FCGIPipe: ...@@ -791,7 +814,6 @@ class FCGIPipe:
self.recType = recType self.recType = recType
self.length = 0 self.length = 0
def write(self, data): def write(self, data):
if type(data)==type(''): if type(data)==type(''):
datalen = len(data) datalen = len(data)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment