layout | title |
---|---|
default |
Logging |
With the built-in webserver you can control logging by using wsgilog and passing it to your app as middleware.
You need to subclass wsgilog.WsgiLog to pass keyword arguments to the base e.g. this example
import sys, logging
from wsgilog import WsgiLog, LogIO
import config
class Log(WsgiLog):
def __init__(self, application):
WsgiLog.__init__(
self,
application,
logformat = '%(message)s',
tofile = True,
file = config.log_file,
interval = config.log_interval,
backups = config.log_backups
)
sys.stdout = LogIO(self.logger, logging.INFO)
sys.stderr = LogIO(self.logger, logging.ERROR)
Then when you run your app, you pass a reference to to the class e.g. (if the above was part of the module 'mylog';
from mylog import Log
application = web.application(urls, globals())
application.run(Log)