Created
September 6, 2012 10:52
-
-
Save iurisilvio/3654741 to your computer and use it in GitHub Desktop.
bottle wsgilog with hooks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ python main.py | |
Bottle server starting up (using WSGIRefServer())... | |
Listening on http://127.0.0.1:8080/ | |
Hit Ctrl-C to quit. | |
wsgilog.log: Thu, 06 Sep 2012 07:50:38 INFO Before request to GET /hello/bottle | |
wsgilog.log: Thu, 06 Sep 2012 07:50:38 INFO After request to GET /hello/bottle | |
iurisilvio - - [06/Sep/2012 07:50:38] "GET /hello/bottle HTTP/1.1" 200 20 | |
iurisilvio - - [06/Sep/2012 07:50:38] "GET /favicon.ico HTTP/1.1" 404 742 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bottle | |
from bottle import request | |
from wsgilog import WsgiLog | |
app = bottle.app() | |
@app.route('/hello/<name>') | |
def index(name='World'): | |
return '<b>Hello %s!</b>' % name | |
@app.hook('before_request') | |
def before_request(): | |
print request.path | |
request.environ['wsgilog.logger'].info('Before request to %s %s' % (request.method, request.path)) | |
@app.hook('after_request') | |
def after_request(): | |
request.environ['wsgilog.logger'].info('After request to %s %s' % (request.method, request.path)) | |
app = WsgiLog(app, tostream=True) | |
bottle.debug(True) | |
bottle.run(app=app, reloader=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment