python safe scripting

Simon Hibbs simon.hibbs at gmail.com
Fri Nov 23 13:47:21 EST 2007


> > 2007/11/21, Vladimir Rusinov <vladi... at greenmice.info>:

> Yes, but apache, nginx and others does not uses logger.
> I wanna write an application which would handle all my (Linux) logs:
> rotating, compressing, analysing and so on (logrotate replacement), it would
> require some nontrivial configuration, something like "If size of this log
> bigger then 2Mb or today is sunday. If size of this log bigger then 30 Mb,
> and today is not sunday, then rotate it, and make alert".
> Is there any module to parse such configuration files?

I don't think there's a module for this. Those kinds of tests are
fairly easy though.

import datetime, os

filename = 'myfile.log'
if (datetime.date.today().weekday() == 0) or (os.stat(filename)[6] >
2000000):
    do.whatever()

The individual tests would be better wrapped in utility functions of
course.

Simon Hibbs



More information about the Python-list mailing list