4

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.

tshepang
  • 12,111
  • 21
  • 91
  • 136
Jonathan
  • 41
  • 2
  • I tried it a different way, using `pserve development.ini` and changed `[server:main]` to `use = egg:gunicorn#main` - this works. pserve uses gunicorn, and logs show up correctly. – Jonathan Feb 21 '14 at 08:39

2 Answers2

2

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
fillest
  • 41
  • 1
  • 3
  • still doesn't work for me. I even tried setting up pyramid_exclog but that doesn't work either... – julx Mar 21 '16 at 18:54
  • @julkiewicz how do you launch it? Latest gunicorn versions doesn't ever require `--log-config` anymore and use the same config provided with `--paster`. Either your gunicorn is quite old or there should be some error in your logging configuration – fillest Apr 06 '16 at 18:09
1

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 
Dmitry Vakhrushev
  • 1,382
  • 8
  • 12