I want to simply print a few line breaks (when my application is configured to be verbose) after every request so that I can easily separate them in my console. For example, my current verbose output looks something like this (There are way more debug print lines in the real application):
### webserver->check_login: Checking session cookie for client at 127.0.0.1 ### webserver->check_login: Credentials cookie was valid, client logged in ### webserver->render_secure_page: Rendering 'dashboard.html' 127.0.0.1 - - [05/Aug/2012 15:50:06] "GET /dashboard HTTP/1.1" 200 1728 ### webserver->check_login: Checking session cookie for client at 127.0.0.1 ### webserver->check_login: Credentials cookie was valid, client logged in ### webserver->render_secure_page: Rendering 'dashboard.html' 127.0.0.1 - - [05/Aug/2012 15:50:06] "GET /dashboard HTTP/1.1" 200 1728 ### webserver->check_login: Checking session cookie for client at 127.0.0.1 ### webserver->check_login: Credentials cookie was valid, client logged in ### webserver->render_secure_page: Rendering 'dashboard.html' 127.0.0.1 - - [05/Aug/2012 15:50:06] "GET /dashboard HTTP/1.1" 200 1728
I want it to look like this:
### webserver->check_login: Checking session cookie for client at 127.0.0.1 ### webserver->check_login: Credentials cookie was valid, client logged in ### webserver->render_secure_page: Rendering 'dashboard.html' 127.0.0.1 - - [05/Aug/2012 15:50:06] "GET /dashboard HTTP/1.1" 200 1728 ### webserver->check_login: Checking session cookie for client at 127.0.0.1 ### webserver->check_login: Credentials cookie was valid, client logged in ### webserver->render_secure_page: Rendering 'dashboard.html' 127.0.0.1 - - [05/Aug/2012 15:50:06] "GET /dashboard HTTP/1.1" 200 1728 ### webserver->check_login: Checking session cookie for client at 127.0.0.1 ### webserver->check_login: Credentials cookie was valid, client logged in ### webserver->render_secure_page: Rendering 'dashboard.html' 127.0.0.1 - - [05/Aug/2012 15:50:06] "GET /dashboard HTTP/1.1" 200 1728
Without manually adding the print in all my 100+ views.
Can this be done?
For a quick hack, you could use the hooks plugin.
from bottle import hook
@hook('after_request')
def separator():
print 3 * "\n",
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With