4

The log rotation for Plone product installation would be a nice feature. What are the current best practices regarding the log rotation integration into Plone?

I found this article: http://encolpe.wordpress.com/2010/06/17/how-to-get-log-files-rotate-in-zope-with-buildout/ but as there are no documentation on plone.org I'd like to ping the community for the good known best practices not to fill up their hard disks.

0

5 Answers 5

6

ZConfig has support for the standard library RotatingFileHandler and TimedRotatingFileHandler. Taking an example from the ZConfig tests:

<eventlog>
  <logfile>
    path /path/to/file.log
    level debug
    when D
    interval 3
    old-files 11
  </logfile>
</eventlog>

This will roll over the logs every three days, keeping 11 old files.

You place these config snippets your buildout using the event-log-custom/access-log-custom parameters in your instance recipe. plone.recipe.zope2instance

0
4

Similar to what Laurence said above but keeps size under 10mb and saves only 1 old file.

<eventlog> 
   level INFO 
   <logfile>
     path /path/to/plone4/var/log/client1.log
     max-size 10mb
     old-files 1
   </logfile>
</eventlog>

plone.recipe.zope2instance can generate this now. For example, you can specify the following options:

event-log-max-size = 10mb
event-log-old-files = 3
2

Here's what we do, it's simple but works:

In your buildout you add this part:

[logrotate]
recipe = collective.recipe.template
input =  ${buildout:directory}/templates/logrotate.conf
output = ${buildout:directory}/etc/logrotate.conf

And in templates/logrotate.conf

rotate 4
weekly
create
compress
delaycompress
missingok

${buildout:directory}/var/log/instance1.log ${buildout:directory}/var/log/instance1-Z2.log {
    sharedscripts
    postrotate
        /bin/kill -USR2 $(cat ${buildout:directory}/var/instance1.pid)
    endscript
}

${buildout:directory}/var/log/instance2.log ${buildout:directory}/var/log/instance2-Z2.log {
    sharedscripts
    postrotate
        /bin/kill -USR2 $(cat ${buildout:directory}/var/instance2.pid)
    endscript
}

Add whatever other log rotations you need. Then it's about linking /etc/logrotate.conf to the generated file.

3
  • Again, it's Unix-centric - won't work on Windows. I don't like running Plone/Zope on Windows, but some clients demand it.
    – Auspex
    Feb 27, 2012 at 15:14
  • You're absolutely right, this will only work on unix-like environments. Then again, the question did not ask what is the best cross-platform way to do logrotation, nor what should go to the plone manual. It asked for best practices. In my best practices list, windows is not listed. I can totally see why you downvote it from your point of view, don't get me wrong. In any case I will stop replying to this troll-type questions we start having recently, it's a waste of stackoverflow resources and my energy.
    – ggozad
    Feb 27, 2012 at 15:25
  • it's hardly fair to call this a "troll-type question" - it's a perfectly good question, and I'm pleased to have learned from it that logrotation is now built-in to Zope. And while I agree with you that running Zope on Windows is hardly best-practice, I can't accept that a best practice for log rotation involves a method that can't work on all platforms supported by Zope.
    – Auspex
    Feb 28, 2012 at 15:55
2

Mikko, you should ask me directly ;)

My blog article is still good and this feature is still undocumented in Zope2. It can be used with Plone 4 and Plone 5. The extension iw.rotatelogs was designed for Plone 3 only.

Using logrotate is not fine because it doesn't handle the case of logwriting during the rotation. It can make your instance crash silently and writing logs in RAM until your restart the instance.

1

I've been using iw.rotatezlogs since at least early Plone 3 very successfully. I see from your link that I should no longer need iw.rotatezlogs.

I don't like to rely on logrotate, since it's not usable on the one Windows server I have to deploy to.

As near as I can tell, the pure-zope solution (which I stil haven't tested) doesn't do logfile compression (at least I can't see it in ZConfig/components/logger/handlers.xml which is where I think it should be defined), so I suspect I'll be staying with iw.rotatezlogs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.