Commit 864e310f authored by Arnaud Fontaine's avatar Arnaud Fontaine

zope4: Configure logging similarly to what ZConfig used to do.

zope.conf of Zope2 (zopeschema.xml) used to define event/Z2 log files and
properly configure logging but this is not the case anymore with
Zope4 (wsgischema.xml).

This adds path to event/Z2 log files as command line parameter as we probably
don't need further configuration such as message format (SlapOS recipe has never
handled it anyway).
parent 5d3e5f7c
...@@ -164,6 +164,8 @@ def createServer(application, logger, **kw): ...@@ -164,6 +164,8 @@ def createServer(application, logger, **kw):
def runwsgi(): def runwsgi():
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('-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')
...@@ -177,6 +179,37 @@ def runwsgi(): ...@@ -177,6 +179,37 @@ def runwsgi():
schema = ZConfig.loadSchema(os.path.join(startup, 'zopeschema.xml')) 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 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:
...@@ -200,7 +233,7 @@ def runwsgi(): ...@@ -200,7 +233,7 @@ def runwsgi():
large_file_threshold=getattr(conf, 'large_file_threshold', None), large_file_threshold=getattr(conf, 'large_file_threshold', None),
webdav_ports=[port] if args.webdav else ()), webdav_ports=[port] if args.webdav else ()),
listen=args.address, listen=args.address,
logger=logging.getLogger("access"), logger=access_log_logger,
threads=getattr(conf, 'zserver_threads', 4), threads=getattr(conf, 'zserver_threads', 4),
asyncore_use_poll=True, asyncore_use_poll=True,
# Prevent waitress from adding its own Via and Server response headers. # Prevent waitress from adding its own Via and Server response headers.
......
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