To answer my question about how to set up the log handlers for the global log instead of the app-level log, here are the changes:
cherrypy.config.update({'server.socket_host': '0.0.0.0',
'server.socket_port': 1234,
'tools.staticdir.on': True,
'tools.staticdir.dir': script_dir,
'log.access_file': "access1.log",
'log.error_file': "error1.log",
'log.screen': True,
'tools.sessions.on': True,
})
config = {'/':
{
}
}
application = cherrypy.tree.mount(HealthCheck(script_dir, service_fqdn, my_ip), "/", config)
logscope = cherrypy.log
# Make a new RotatingFileHandler for the error log.
fname = getattr(logscope, "rot_error_file", "error.log")
h = handlers.TimedRotatingFileHandler(fname, when='midnight')
h.setLevel(logging.DEBUG)
h.setFormatter(_cplogging.logfmt)
logscope.error_file = ""
logscope.error_log.addHandler(h)
# Make a new RotatingFileHandler for the access log.
fname = getattr(logscope, "rot_access_file", "access.log")
h = handlers.TimedRotatingFileHandler(fname, when='midnight')
h.setLevel(logging.DEBUG)
h.setFormatter(_cplogging.logfmt)
logscope.access_file = ""
logscope.access_log.addHandler(h)
or, in a nutshell:
- leave the application config empty. I'm only defining it so that CherryPy starts quietly.
- change the log scope from application.log to cherrypy.log
To be slightly more tidy, the references to access1.log and error1.log can change to access.log and error.log but I left them like that to confirm that I was overwriting the global settings.