Skip to content

Instantly share code, notes, and snippets.

@natefoo
Created July 15, 2015 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save natefoo/7c9c072e4e46225028f8 to your computer and use it in GitHub Desktop.
Save natefoo/7c9c072e4e46225028f8 to your computer and use it in GitHub Desktop.
uWSGI log buffer/truncate example
[uwsgi]
processes = 2
socket = 127.0.0.1:4002
master = True
logto = uwsgi.log
threads = 2
single-interpreter = True
log-master = True
module = app:WebApplication()
import sys
import logging
log = logging.getLogger(__name__)
log_format = "%(name)s %(levelname)s %(asctime)s %(message)s"
log_level = logging._levelNames["DEBUG"]
log.info("Logging at '%s' level to stdout", log_level)
root = logging.getLogger()
root.setLevel(log_level)
for h in root.handlers[:]:
root.removeHandler(h)
handler = logging.StreamHandler(sys.stdout)
formatter = logging.Formatter(log_format)
handler.setFormatter(formatter)
root.addHandler(handler)
class WebApplication(object):
def __init__(self):
for i in range(0, 1024):
log.info('############ this line is approximately 128 bytes long including newline, iteration number %0.4d', i)
def __call__(self, environ, start_response):
start_response('200 OK', [('Content-Type','text/html')])
return ['foo']
def return_app( conf, **kwargs ):
log.debug('called from return_app()')
log.debug('conf: %s', conf)
log.debug('kwargs: %s', kwargs)
return WebApplication()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment