Achim
Achim

Reputation: 15722

Cannot get logging to work when running Pyramid app with uwsgi

I have a Pyramid application, which works fine, when started via pserve or via uwsgi. When started via pserve, my logging setup works fine, but not when started via uwsgi. The uwsgi section of my paster ini looks like this:

[uwsgi]
socket = 127.0.0.1:3099
master = True
processes = 1
virtualenv = /opt/data/virtualenvs/some_virtual_env
paste = config:%p
paste-logger = True
buffer-size = 65535

I found of course this question and also tried to configure the logger like this:

paste-logger = %p

But is does not work. My logging config is using an absolute path and the target folder of the log file allows reading and writing for everybody. I wonder a little bit about how to specify paste-logger, because it has no argument according to the documentation.

The command line configuration for upstart is defined like this:

exec uwsgi --master --die-on-term --emperor /etc/uwsgi/apps-enabled

No custom log files are created and in the uwsgi log I don't see any helpful messages or errors. Any help how to get logging working or to debug the problem would be very appreciated.

Upvotes: 0

Views: 1852

Answers (1)

Dmitry Vakhrushev
Dmitry Vakhrushev

Reputation: 1382

This is not exactly what you asked about, but the following works for me on Ubuntu.

I use default logging configuration provided by Pyramid templates, which streams logs into stderr:

# Begin logging configuration

[loggers]
keys = root, myapp

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = INFO
handlers = console

[logger_myapp]
level = DEBUG
handlers =
qualname = myapp

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

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

# End logging configuration

Each uWSGI application in Ubuntu has its own config file, which should be placed in /etc/uwsgi/apps-enabled/ directory. Here myapp.ini for example:

[uwsgi]
plugin = python
virtualenv = /path/to/myapp/virutalenv
paste = config:/path/to/myapp/config.ini

So when I run application using pserve command I will get logs in console. When I run it using uWSGI, uWSGI will create output logs into /var/log/uwsgi/app/myapp.log

UPDATE

I just dug around uWSGI configs and found a place, where log file location is set up. uWSGI init.d scripts use daemonize argument:

--daemonize "/var/log/uwsgi/${CONFNAMESPACE}/${CONFNAME}.log"

UPDATE 2

It may be helpful in your case to explicitly setup logging in your application:

from pyramid.paster import setup_logging

setup_logging("/path/to/config.ini")

Upvotes: 3

Related Questions