Commit 9f9294a8 authored by Levin Zimmermann's avatar Levin Zimmermann

.

parent 483dc85d
...@@ -81,6 +81,8 @@ class TransLogger(object): ...@@ -81,6 +81,8 @@ class TransLogger(object):
def app_wrapper(large_file_threshold=10<<20, webdav_ports=()): def app_wrapper(large_file_threshold=10<<20, webdav_ports=()):
if large_file_threshold is None:
large_file_threshold = 10<<20
try: try:
from Products.DeadlockDebugger.dumper import dump_threads, dump_url from Products.DeadlockDebugger.dumper import dump_threads, dump_url
except Exception: except Exception:
...@@ -242,8 +244,6 @@ def runwsgi(): ...@@ -242,8 +244,6 @@ def runwsgi():
ident=None, ident=None,
).run() ).run()
server = None
################################################################ ################################################################
# #
# Please read the code below. # Please read the code below.
...@@ -257,11 +257,15 @@ from twisted.web.wsgi import WSGIResource ...@@ -257,11 +257,15 @@ from twisted.web.wsgi import WSGIResource
from twisted.internet import protocol, reactor, endpoints from twisted.internet import protocol, reactor, endpoints
from twisted.web import server as twisted_server from twisted.web import server as twisted_server
from io import StringIO from io import StringIO
import urllib
# I modified runwsgi() without thinking carefully. # I modified runwsgi() without thinking carefully.
# Very dirty code. # Very dirty code.
def runwsgitw(): def runwsgitw():
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('--event-log-file', help='Event log file')
parser.add_argument('--access-log-file', help='Access log file')
parser.add_argument('--long-request-log-file', help='Long requests log file')
parser.add_argument('-w', '--webdav', action='store_true') parser.add_argument('-w', '--webdav', action='store_true')
parser.add_argument('address', help='<ip>:<port>') parser.add_argument('address', help='<ip>:<port>')
parser.add_argument('zope_conf', help='path to zope.conf') parser.add_argument('zope_conf', help='path to zope.conf')
...@@ -269,9 +273,50 @@ def runwsgitw(): ...@@ -269,9 +273,50 @@ def runwsgitw():
args = parser.parse_args() args = parser.parse_args()
startup = os.path.dirname(Zope2.Startup.__file__) startup = os.path.dirname(Zope2.Startup.__file__)
schema = ZConfig.loadSchema(os.path.join(startup, 'zopeschema.xml')) if os.path.isfile(os.path.join(startup, 'wsgischema.xml')):
schema = ZConfig.loadSchema(os.path.join(startup, 'wsgischema.xml'))
else: # BBB
schema = ZConfig.loadSchema(os.path.join(startup, 'zopeschema.xml'))
conf, _ = ZConfig.loadConfig(schema, args.zope_conf) conf, _ = ZConfig.loadConfig(schema, args.zope_conf)
# Configure logging previously handled by ZConfig/ZServer
logging.captureWarnings(True)
root_logger = logging.getLogger()
root_logger.setLevel(logging.INFO)
if args.event_log_file is None:
event_log_handler = logging.StreamHandler(sys.stdout)
else:
event_log_handler = logging.FileHandler(args.event_log_file)
event_log_handler.setFormatter(logging.Formatter(
"------\n%(asctime)s,%(msecs)d %(levelname)s %(name)s %(message)s",
"%Y-%m-%d %H:%M:%S"))
root_logger.addHandler(event_log_handler)
if args.access_log_file is None:
access_log_handler = logging.StreamHandler(sys.stdout)
else:
access_log_handler = logging.FileHandler(args.access_log_file)
access_log_handler.setLevel(logging.INFO)
access_log_logger = logging.getLogger('access')
access_log_logger.propagate = False
access_log_logger.addHandler(access_log_handler)
if args.long_request_log_file:
from Products.ERP5Type.patches import LongRequestLogger_dumper
long_request_log_handler = logging.FileHandler(args.long_request_log_file)
long_request_log_handler.setFormatter(logging.Formatter("%(asctime)s - %(message)s"))
LongRequestLogger_dumper.logger.propagate = False
LongRequestLogger_dumper.logger.addHandler(long_request_log_handler)
if conf.debug_mode:
console_handler = logging.StreamHandler(sys.stderr)
console_handler.setFormatter(logging.Formatter(
"%(asctime)s,%(msecs)d %(levelname)s %(name)s %(message)s",
"%Y-%m-%d %H:%M:%S"))
console_handler.setLevel(logging.NOTSET)
root_logger.addHandler(console_handler)
make_wsgi_app({}, zope_conf=args.zope_conf) make_wsgi_app({}, zope_conf=args.zope_conf)
if six.PY2: if six.PY2:
...@@ -293,17 +338,21 @@ def runwsgitw(): ...@@ -293,17 +338,21 @@ def runwsgitw():
# Let's add Twisted. I do not use waitress. # Let's add Twisted. I do not use waitress.
# #
################################################# #################################################
ip, port = splitport(args.address) ip, port = urllib.parse.splitport(args.address)
port = int(port) port = int(port)
# Keep ERP5 original implementation. # Keep ERP5 original implementation.
# This is ERP5 wsgi interface, it means that this is # This is ERP5 wsgi interface, it means that this is
# the entrance of ERP5. # the entrance of ERP5.
translogger = TransLogger( translogger = TransLogger(
app_wrapper( app_wrapper(
large_file_threshold=conf.large_file_threshold, large_file_threshold=getattr(conf, 'large_file_threshold', None),
webdav_ports=[port] if args.webdav else ()), webdav_ports=[int(args.address.rsplit(':', 1)[1])] if args.webdav else ()
logger=logging.getLogger("access")) ),
logger=access_log_logger,
# threads=getattr(conf, 'zserver_threads', 4)
# listen=args.address,
)
# Let's use twisted's wsgi wrapper. # Let's use twisted's wsgi wrapper.
resource = WSGIResource( resource = WSGIResource(
......
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