[Plone 5.2] Logrotate not working

Hi,

I am trying to make the logrotate mechanism work like it is described here: https://docs.plone.org/manage/deploying/logs.html
Unfortunately adding these lines into [instance_base] section makes no difference:

event-log-max-size = 5 MB
event-log-old-files = 5
access-log-max-size = 20 MB
access-log-old-files = 10

I can also not see any changes in parts/client1/etc/zope.cfg, size.zcml or wsgi.ini after a buildout. Am I doing something wrong here? In an other project I am using the logrotate daemon of the OS but in this project I want it to have defined within the user space.

Is there something I missed?

Python 3, Plone 5.2, WSGI requires a different approach

Thank you, but this does not seem to work correctly. I can not start my client anymore. This is the configuration in buildout.cfg:

event-log-handler = logging.handlers.TimedRotatingFileHandler
event-log-kwargs = {"when": "D", "interval": 1, "backupCount": 14}

access-log-handler = logging.handlers.TimedRotatingFileHandler
access-log-kwargs = {"when": "D", "interval": 1, "backupCount": 14}

And this is the error I get on startup:

Traceback (most recent call last):
  File "/home/htw/plone/zinstance/parts/client6/bin/interpreter", line 314, in <module>
    exec(compile(__file__f.read(), __file__, "exec"))
  File "/home/htw/plone/buildout-cache/eggs/Zope-4.1.3-py3.8.egg/Zope2/Startup/serve.py", line 255, in <module>
    sys.exit(main() or 0)
  File "/home/htw/plone/buildout-cache/eggs/Zope-4.1.3-py3.8.egg/Zope2/Startup/serve.py", line 251, in main
    return command.run()
  File "/home/htw/plone/buildout-cache/eggs/Zope-4.1.3-py3.8.egg/Zope2/Startup/serve.py", line 180, in run
    setup_logging(log_fn, global_conf=vars)
  File "/home/htw/plone/buildout-cache/eggs/Zope-4.1.3-py3.8.egg/Zope2/Startup/serve.py", line 78, in setup_logging
    return fileConfig(
  File "/usr/lib/python3.8/logging/config.py", line 79, in fileConfig
    handlers = _install_handlers(cp, formatters)
  File "/usr/lib/python3.8/logging/config.py", line 145, in _install_handlers
    h = klass(*args, **kwargs)
TypeError: __init__() got multiple values for argument 'when'

Please file a bug report (zope2instance repo) and assign it to me (zopyx).

I think there is already one: https://github.com/plone/plone.recipe.zope2instance/issues/119

By the way we are using a custom wsgi.ini template and this snippet works as expected:

[handler_accesslog]
class = logging.handlers.TimedRotatingFileHandler
args = ("/path/to/var/log/instance1-Z2.log",)
kwargs = {"when": "D", "interval": 1, "backupCount": 14}
level = INFO
formatter = message

If that is the same reason as I am experiencing then I could add my bug report to the same issue. In the other case I could create a new one. For the moment I subscribed to #119 to get a notification if it is fixed.

I guess the issue is that when is the second parameter of logging.handlers.TimedRotatingFileHandler. And if I omit the definition of event-log-args it uses the default which is a tuple of two values. The second one of them already sets the parameter when to the value "a".

Long story short. It should work like this and I will check this out:

access-log-args = (r"{}",)

I can confirm that it works now.
So the fix is to change this line


into this:
            accesslog_args = "(r'{}')".format(accesslog_name)

And also change the documentation.

1 Like

My workaround is to set access and event log args:

access-log-handler = logging.handlers.TimedRotatingFileHandler
access-log-args = (r"${buildout:directory}/var/log/${:_buildout_section_name_}-access.log",)
access-log-kwargs = {"when": "D", "interval": 1}

event-log-handler = logging.handlers.TimedRotatingFileHandler
event-log-args = (r"${buildout:directory}/var/log/${:_buildout_section_name_}.log",)
event-log-kwargs = {"when": "D", "interval": 1}