10

I am trying to setup logging for a Python Pyramid Waitress Server. I have followed the docs here: Pyramid logging and here: Pyramid PasteDeploy logging. I have tired both methods which have yield no logging results from waitress. My own logging works perfectly.

I have set Waitress logging level to DEBUG and I get nothing even I remove server files. Waitress fails server silently.

How do you set up logging for a Pyramid Waitress Server so I can see files be requested, missing file errors, etc?

Method 1: Setup from code:

import logging
logging.basicConfig()
logger = logging.getLogger('waitress')
logger.setLevel(logging.DEBUG)

Method 2: Starting the server with pserve development.ini where the development.ini file sets up the logging as below

[app:main]
use = egg:MyProject

pyramid.reload_templates = true
pyramid.debug_authorization = false
pyramid.debug_notfound = false
pyramid.debug_routematch = false
pyramid.default_locale_name = en
pyramid.includes =
pyramid_debugtoolbar

[server:main]
use = egg:waitress#main
host = 0.0.0.0
port = 6543



[loggers]
keys = root, myproject, waitress

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = INFO
handlers = console

[logger_myproject]
level = DEBUG
handlers =
qualname = myproject


[logger_waitress]
level = DEBUG
handlers =
qualname = waitress


[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
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
fat fantasma
  • 7,483
  • 15
  • 48
  • 66
  • 1
    No log from your console, isn't ? – Ali SAID OMAR Dec 27 '13 at 19:30
  • I only get logging from 'myproject' to the console. Absolutely nothing comes from Waitress logging. I would think I would get at least something when set to DEBUG. – fat fantasma Dec 28 '13 at 00:12
  • See here also: https://stackoverflow.com/questions/41175887/how-do-i-redirect-python-pyramid-waitress-logging-to-stdout-on-heroku/41195185#41195185 – Jeremy T Dec 17 '16 at 03:48

2 Answers2

5

The logging configuration actually works. Here I demonstrate a simple view to emit logging message for waitress logger

@view_config(route_name='hello_baby', 
             request_method='GET', 
             renderer='string')
def hello_baby(request):
    import logging
    logger = logging.getLogger('waitress')
    logger.info('Hello baby!')
    return 'Hi there'

You should be able to see the logging message when you hit the page. The reason you didn't see messages from waitress is - there is no logging messages are emitted for common routines in waitress. It only emits messages when something goes wrong, you can read the source code

For some other knowledge about Python logging, you can read my article : Good logging practice in Python

Sascha Gottfried
  • 3,303
  • 20
  • 30
Fang-Pen Lin
  • 13,420
  • 15
  • 66
  • 96
  • Victor, thanks for responding. I actually read your awesome logging article last month :) That's was my first introduction into logging. I had a feeling that I was not asking the correct question but being new to all of this it's hard to know. I'm surprised to learn that waitress doesn't do any logging or error output. As a test, I removed some static files from my server and waitress failed silently. No 'file not found' or anything. I need to post another question. I really wanted to log static file requests. I guess I need to set that up in Pyramid and do it manually. – fat fantasma Dec 30 '13 at 01:10
2

I got console logging (for all requests) to show up by using paste's translogger; A good example is at http://flask.pocoo.org/snippets/27/.

Here's the relevant section of my .ini:

[app:main]
use = egg:${:app}
filter-with = translogger

[filter:translogger]
use = egg:Paste#translogger
# these are the option default values (see http://pythonpaste.org/modules/translogger.html)
# logger_name='wsgi'
# format=None
# logging_level=20
# setup_console_handler=True
# set_logger_level=10
RoyM
  • 1,118
  • 1
  • 9
  • 28