Question

I am starting gunicorn with the --paster option for running Pyramid.

gunicorn -w 1 --paster development.ini

gunicorn's own messages show up fine on console, for example

2014-02-20 22:38:50 [44201] [INFO] Starting gunicorn 18.0
2014-02-20 22:38:50 [44201] [INFO] Listening at: http://0.0.0.0:6543 (44201)
2014-02-20 22:38:50 [44201] [INFO] Using worker: sync

However the log messages in my Pyramid app are not showing up.

If I use pserve development.ini, which uses waitress as WSGI server, the log messages show up on console just fine.

My development.ini includes a pretty vanilla logging configuration section.

[loggers]
keys = root, apipython

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = INFO
handlers = console

[logger_apipython]
level = DEBUG
handlers =
qualname = apipython

[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = DEBUG
formatter = generic

[formatter_generic]
format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s

I am at lost why the logs are not showing up when I use gunicorn.

No correct solution

OTHER TIPS

Do not use pserve with gunicorn, it is deprecated and most likely will be removed in some of the next versions.

Gunicorn has "logconfig" setting, just set it to your config via command line argument:

gunicorn -w 1 --paster development.ini --log-config development.ini

or in the same config:

[server:main]
use = egg:gunicorn#main
logconfig = %(here)s/development.ini

It happens because of "pserve" command not only starts server and loads application, it also setups logging. While "gunicorn --paster" just loads application. To fix it you can explicitly setup logging on your application:

from pyramid.config import Configurator
from pyramid.paster import setup_logging

def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application. """
    setup_logging(global_config['__file__'])
    config = Configurator(settings=settings)
    # Configure application 
    return config.make_wsgi_app()

Or as you pointed in comment, change server in config file and use "pserve" command:

[server:main]
use = egg:gunicorn#main 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top