Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore file based logging for waitress #76

Merged
merged 4 commits into from Mar 4, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion CHANGES.rst
Expand Up @@ -24,7 +24,6 @@ Breaking changes:

Bug fixes:


- log level for Plone WSGI logger changed to INFO making the logging less
verbose [ajung] (#66)
- Improve debugging of run scripts by providing the source code for the
Expand Down
14 changes: 7 additions & 7 deletions README.rst
Expand Up @@ -224,12 +224,11 @@ log levels or configure `mailinglogger`.
event-log
The filename of the event log. Defaults to ${buildout:directory}/var/log/${partname}.log
Setting this value to 'disable' will make the <eventlog> section to be omitted,
disabling logging events by default to a .log file. Used for ZServer only, not WSGI.
disabling logging events by default to a .log file.

event-log-level
Set the level of the console output for the event log. Level may be any of
CRITICAL, ERROR, WARN, INFO, DEBUG, or ALL. Defaults to INFO.
Used for ZServer only, not WSGI.

event-log-max-size
Maximum size of event log file. Enables log rotation.
Expand Down Expand Up @@ -258,14 +257,15 @@ mailinglogger

You will need to add `mailinglogger` to your buildout's egg section to make this work.

z2-log
The filename for the Z2 access log. Defaults to var/log/${partname}-Z2.log.
access-log, z2-log
The filename for the Z2 access log. Defaults to var/log/${partname}-Z2.log
(var/log/${partname}-access.log) for WSGI).
Setting this value to 'disable' will make the <logger access> section to be omitted,
disabling logging access events to a .log file. Used for ZServer only, not WSGI.
disabling logging access events to a .log file.

z2-log-level
access-log-level, z2-log-level
Set the log level for the access log. Level may be any of CRITICAL, ERROR,
WARN, INFO, DEBUG, or ALL. Defaults to WARN. Used for ZServer only, not WSGI.
WARN, INFO, DEBUG, or ALL. Defaults to WARN (INFO for WSGI).

access-log-max-size
Maximum size of access log file. Enables log rotation.
Expand Down
2 changes: 2 additions & 0 deletions news/76.bugfix
@@ -0,0 +1,2 @@
Restore log files for waitress.
[tschorr]
1 change: 1 addition & 0 deletions setup.py
Expand Up @@ -43,6 +43,7 @@
'Zope >= 4.0b1',
'ZODB >= 5.1.1',
'ZEO',
'Paste',
],
extras_require={
'test': [
Expand Down
84 changes: 75 additions & 9 deletions src/plone/recipe/zope2instance/recipe.py
Expand Up @@ -333,7 +333,9 @@ def build_zope_conf(self):
}

z_log_name = os.path.sep.join(('log', self.name + '-Z2.log'))
z_log_name = options.get('z2-log', z_log_name)
z_log_name = options.get(
'z2-log',
options.get('access-log', z_log_name))
if z_log_name.lower() == 'disable':
access_event_log = ''
else:
Expand Down Expand Up @@ -661,10 +663,48 @@ def build_wsgi_ini(self):
listen = options.get('http-address', '0.0.0.0:8080')
if ':' not in listen:
listen = '0.0.0.0:{}'.format(listen)

base_dir = self.buildout['buildout']['directory']
var_dir = options.get('var', os.path.join(base_dir, 'var'))
default_eventlog = os.path.sep.join(
(var_dir, 'log', '{}.log'.format(self.name),))
eventlog_name = options.get('event-log', default_eventlog)
eventlog_level = options.get('event-log-level', 'INFO')

if eventlog_name.lower() == 'disable':
root_handlers = 'console'
event_handlers = ''
else:
root_handlers = 'console, eventlog'
event_handlers = 'eventlog'

default_accesslog = os.path.sep.join(
(var_dir, 'log', '{}-access.log'.format(self.name),))

accesslog_name = options.get(
'z2-log',
options.get('access-log', default_accesslog))
accesslog_level = options.get(
'access-log-level',
options.get('z2-log-level', 'INFO'))

if accesslog_name.lower() == 'disable':
pipeline = '\n '.join(['egg:Zope#httpexceptions', 'zope'])
event_handlers = ''
else:
pipeline = '\n '.join(
['translogger', 'egg:Zope#httpexceptions', 'zope'])
options = {
'location': options['location'],
'http_address': listen,
'threads': options.get('threads', 4),
'eventlog_name': eventlog_name,
'root_handlers': root_handlers,
'event_handlers': event_handlers,
'accesslog_name': accesslog_name,
'pipeline': pipeline,
'eventlog_level': eventlog_level,
'accesslog_level': accesslog_level,
}
wsgi_ini = wsgi_ini_template % options
with open(wsgi_ini_path, 'w') as f:
Expand Down Expand Up @@ -1197,35 +1237,61 @@ def render_file_storage(self, file_storage, blob_storage,
use = egg:Zope#main
zope_conf = %(location)s/etc/zope.conf

[filter:translogger]
use = egg:Paste#translogger
setup_console_handler = False

[pipeline:main]
pipeline =
egg:Zope#httpexceptions
zope
%(pipeline)s

[loggers]
keys = root, plone
keys = root, plone, waitress, wsgi

[handlers]
keys = console
keys = console, accesslog, eventlog

[formatters]
keys = generic

[logger_root]
level = INFO
handlers = console
level = %(eventlog_level)s
handlers = %(root_handlers)s

[logger_plone]
level = INFO
handlers =
level = %(eventlog_level)s
handlers = %(event_handlers)s
qualname = plone

[logger_waitress]
level = %(eventlog_level)s
handlers = %(event_handlers)s
qualname = waitress

[logger_wsgi]
level = %(accesslog_level)s
handlers = accesslog
qualname = wsgi
propagate = 0

[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic

[handler_accesslog]
class = FileHandler
args = ('%(accesslog_name)s','a')
level = %(accesslog_level)s
formatter = generic

[handler_eventlog]
class = FileHandler
args = ('%(eventlog_name)s', 'a')
level = NOTSET
formatter = generic

[formatter_generic]
format = %%(asctime)s %%(levelname)-5.5s [%%(name)s:%%(lineno)s][%%(threadName)s] %%(message)s
tschorr marked this conversation as resolved.
Show resolved Hide resolved
""" # noqa: E501