Timothy Shead wrote:
> cherrypy.log.access_log.handlers = []
> cherrypy.log.access_log.addHandler(logging.handlers.RotatingFileHandler(my_log_path, "a", my_log_size, my_log_count))
> ... this has worked great for years. However, I recently
> also had to start dropping privileges so I could bind to
> a low-numbered port:
>
> cherrypy.process.plugins.DropPrivileges(cherrypy.engine, uid=my_uid, gid=my_gid, umask=my_umask).subscribe()
>
> Now, I'm running into a problem where, if they don't already
> exist, my log files are created owned by root, and then
> cherrypy can't write to them after it drops privileges,
> causing every request to fail. It seems that I need to
> defer logfile creation until after the privileges have
> been dropped, but I assume that others would have run
> into this before now, any suggestions?
Hi Tim,
The recommended solution here is to wrap up your handler calls in a plugin and then subscribe it to run after the drop.
class Logging(plugins.SimplePlugin):
def start(self):
cherrypy.log.access_log.handlers = []
rfh = logging.handlers.RotatingFileHandler(
my_log_path, "a", my_log_size, my_log_count)
cherrypy.log.access_log.addHandler(rfh)
start.priority = 80
cherrypy.engine.mylogging = Logging(cherrypy.engine)
cherrypy.engine.mylogging.subscribe()
See
http://docs.cherrypy.org/stable/progguide/extending/customplugins.html for more details. There are ways to pass in config this way too.
Robert Brewer
fuma...@aminus.org