gunicorn/examples/log_app.py
benoitc 66f7271c5f Use our own logger object to log events in gunicorn. While I'm here add
the possibility to manage an access log compatible with apache combined
log format. reopening files is also handled. Also, this change fix
issues #237 and #190.

For the sake of simplicity logging file have been removed

--logfile option has become --error-logfile, by default "-"

Following options have been added:

--access-logfile, the access log file path. By default None. If set
access logs will bre written to defined output

eg:

$ gunicorn -w3 --access-logfile=- test:app
2011-08-21 19:36:52 [84572] [INFO] Starting gunicorn 0.13.0
2011-08-21 19:36:52 [84572] [INFO] Listening at: http://127.0.0.1:8000
(84572)
2011-08-21 19:36:52 [84572] [INFO] Using worker: sync
2011-08-21 19:36:52 [84573] [INFO] Booting worker with pid: 84573
2011-08-21 19:36:52 [84574] [INFO] Booting worker with pid: 84574
2011-08-21 19:36:52 [84575] [INFO] Booting worker with pid: 84575
127.0.0.1 - - [21/Aug/2011:19:37:04] "GET / HTTP/1.1" 200 14 "-"
"curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4 OpenSSL/0.9.8r
zlib/1.2.5"
2011-08-21 21:08:58 +02:00

17 lines
371 B
Python

import logging
log = logging.getLogger(__name__)
log.addHandler(logging.StreamHandler())
def app_factory(global_options, **local_options):
return app
def app(environ, start_response):
start_response("200 OK", [])
log.debug("Hello Debug!")
log.info("Hello Info!")
log.warn("Hello Warn!")
log.error("Hello Error!")
return ["Hello World!\n"]