Skip to content

Instantly share code, notes, and snippets.

@iurisilvio
Created September 6, 2012 10:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iurisilvio/3654741 to your computer and use it in GitHub Desktop.
Save iurisilvio/3654741 to your computer and use it in GitHub Desktop.
bottle wsgilog with hooks
$ 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
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