PylonsHQ.

Layout: Fixed-width

Logging under mod_wsgi

Skip to end of metadata
Go to start of metadata

To have logging(like one has under paster) under mod_wsgi one has to initialize logging on the mod_wsgi's app.wsgi.

Let's suposed you have your app.wsgi inside the project's dir, where you also find setup.py.

Here's an example /path/to/project/dir/app.wsgi:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
import os, sys
from paste.script.util.logging_config import fileConfig

BASEDIR = os.path.dirname(__file__)
INIFILE = os.path.join(BASEDIR, 'production.ini')

sys.path.append(BASEDIR)

os.environ['PYTHON_EGG_CACHE'] = '/var/tmp'

fileConfig( INIFILE )

from paste.deploy import loadapp

application = loadapp('config:%s' % INIFILE))

Now you have to setup the logger handlers for your /path/to/project/dir/production.ini:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Logging configuration
[loggers]
keys = root, <app_name>

[handlers]
keys = file

[formatters]
keys = generic

[logger_root]
level = ERROR
handlers = file

[logger_<app_name>]
level = DEBUG
handlers = file
qualname = <app_name>

[handler_file]
class = handlers.RotatingFileHandler
args = ('/path/to/project/dir/app.log', 'a', 2048, 3)

Please refer to the python documentation regarding the rotating file handler arguments.

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Oct 02, 2008

    Junya HAYASHI says:

    I failed to use pylons.log.WSGIErrorsHandler. My apache's error_log is following...

    I failed to use pylons.log.WSGIErrorsHandler. My apache's error_log is following.

    [Thu Oct 02 15:22:37 2008] [error] Traceback (most recent call last):
    [Thu Oct 02 15:22:37 2008] [error]   File "/usr/local/myapp/lib/python2.4/site-packages/Pylons-0.9.6.2-py2.4.egg/pylons/log.py", line 64, in emit
    [Thu Oct 02 15:22:37 2008] [error]     stream.write(fs % msg)
    [Thu Oct 02 15:22:37 2008] [error] RuntimeError: log object has expired
    [Thu Oct 02 15:22:37 2008] [error] Traceback (most recent call last):
    [Thu Oct 02 15:22:37 2008] [error]   File "/usr/local/myapp/lib/python2.4/site-packages/Pylons-0.9.6.2-py2.4.egg/pylons/log.py", line 64, in emit
    [Thu Oct 02 15:22:37 2008] [error]     stream.write(fs % msg)
    [Thu Oct 02 15:22:37 2008] [error] RuntimeError: log object has expired
    [Thu Oct 02 15:22:37 2008] [error] Traceback (most recent call last):
    [Thu Oct 02 15:22:37 2008] [error]   File "/usr/local/myapp/lib/python2.4/site-packages/Pylons-0.9.6.2-py2.4.egg/pylons/log.py", line 64, in emit
    [Thu Oct 02 15:22:37 2008] [error]     stream.write(fs % msg)
    [Thu Oct 02 15:22:37 2008] [error] RuntimeError: log object has expired
    [Thu Oct 02 15:22:37 2008] [error] Traceback (most recent call last):
    [Thu Oct 02 15:22:37 2008] [error]   File "/usr/local/myapp/lib/python2.4/site-packages/Pylons-0.9.6.2-py2.4.egg/pylons/log.py", line 64, in emit
    [Thu Oct 02 15:22:37 2008] [error]     stream.write(fs % msg)
    [Thu Oct 02 15:22:37 2008] [error] RuntimeError: log object has expired
    [Thu Oct 02 15:22:37 2008] [error] Traceback (most recent call last):
    [Thu Oct 02 15:22:37 2008] [error]   File "/usr/local/myapp/lib/python2.4/site-packages/Pylons-0.9.6.2-py2.4.egg/pylons/log.py", line 64, in emit
    [Thu Oct 02 15:22:37 2008] [error]     stream.write(fs % msg)
    [Thu Oct 02 15:22:37 2008] [error] RuntimeError: log object has expired
    [Thu Oct 02 15:22:37 2008] [error] Traceback (most recent call last):
    [Thu Oct 02 15:22:37 2008] [error]   File "/usr/local/myapp/lib/python2.4/site-packages/Pylons-0.9.6.2-py2.4.egg/pylons/log.py", line 64, in emit
    [Thu Oct 02 15:22:37 2008] [error]     stream.write(fs % msg)
    [Thu Oct 02 15:22:37 2008] [error] RuntimeError: log object has expired

    Some one succeeds using WSGIErrorsHandler with pylons and mod_wsgi ?

  2. Sep 20, 2010

    Greg Lavallee says:

    This setup worked for me. Thanks!

    This setup worked for me. Thanks!


Powered by Pylons - Contact Administrators