Search code examples
pythonloggingcherrypyopenshift

How to set up logging with Cherrypy?


I am trying to set up logging with Cherrypy on my Openshift python 3.3 app. The 'appserver.log' file only updates until the actual server starts then nothing gets added to the log file. I have read and followed (as far as I know) the documentation at the below links. Still no logging.

CherryPy server errors log

http://docs.cherrypy.org/dev/refman/_cplogging.html

My python code snippet:

def run_cherrypy_server(app, ip, port=8080):
   from cherrypy import wsgiserver
   from cherrypy import config

# log.screen:           Set this to True to have both “error” and “access” messages printed to stdout.
# log.access_file:      Set this to an absolute filename where you want “access” messages written.
# log.error_file:       Set this to an absolute filename where you want “error” messages written.

appserver_error_log = os.path.join(os.environ['OPENSHIFT_HOMEDIR'], 'python', 'logs','appserver_error.log')
appserver_access_log = os.path.join(os.environ['OPENSHIFT_HOMEDIR'], 'python', 'logs','appserver_access.log')



config.update({
        'log.screen': True,
        'log.error_file': appserver_error_log,
        'log.access_file': appserver_access_log
       })

server = wsgiserver.CherryPyWSGIServer(
       (ip, port), app, server_name='www.cherrypy.example')
server.start()

The 'appserver_error.log' and 'appserver_access.log' files actually get created in the proper Openshift python directory. However, no logging information in both of the files appserver_error.log and appserver_access.log.

Everything runs fine but no logging.

Any ideas what I am doing wrong?


Solution

  • The WSGI server itself does not do any logging. The CherryPy engine (which controls process startup and shutdown) writes to the "error" log, and only CherryPy applications (that use CherryPy's Request and Response objects) write to the access log. If you're passing your own WSGI application, you'll have to do your own logging.