Access-log fully customizable
It is hidden by default, but TRANSLOGGER_OPTS can do many things for you
This commit is contained in:
parent
4d6324e328
commit
1d5355c771
2 changed files with 27 additions and 4 deletions
|
@ -1,6 +1,13 @@
|
|||
import logging
|
||||
HOST = 'localhost'
|
||||
PORT = '8000'
|
||||
WSGI_SERVER = 'paste'
|
||||
# pastelog is just "paste", but customized to accept logging options
|
||||
WSGI_SERVER = 'pastelog'
|
||||
# these are pastelog-specific options for logging engine
|
||||
TRANSLOGGER_OPTS = {
|
||||
'logger_name': 'accesslog',
|
||||
'set_logger_level': logging.WARNING,
|
||||
'setup_console_handler': False }
|
||||
WSGI_SERVER_OPTIONS = {}
|
||||
|
||||
DEBUG = True
|
||||
|
|
|
@ -6,13 +6,12 @@ logger = logging.getLogger('server')
|
|||
from functools import partial
|
||||
|
||||
from bottle import Bottle, request, static_file, redirect, abort, response
|
||||
import bottle
|
||||
|
||||
botlog = logging.getLogger('bottle')
|
||||
botlog.setLevel(logging.INFO)
|
||||
botlog.addHandler(logging.StreamHandler(sys.stdout))
|
||||
import bottle
|
||||
bottle._stderr = lambda x: botlog.info(x.strip())
|
||||
del bottle
|
||||
|
||||
from techrec import Rec, RecDB
|
||||
from processqueue import get_process_queue
|
||||
|
@ -330,6 +329,16 @@ class DebugAPI(Bottle):
|
|||
/big/<int:exponent> : returns a 2**n -1 byte content
|
||||
'''
|
||||
|
||||
class PasteLoggingServer(bottle.PasteServer):
|
||||
def run(self, handler): # pragma: no cover
|
||||
from paste import httpserver
|
||||
from paste.translogger import TransLogger
|
||||
handler = TransLogger(handler, **self.options['translogger_opts'])
|
||||
del self.options['translogger_opts']
|
||||
httpserver.serve(handler, host=self.host, port=str(self.port),
|
||||
**self.options)
|
||||
bottle.server_names['pastelog'] = PasteLoggingServer
|
||||
|
||||
|
||||
def main_cmd(*args):
|
||||
"""meant to be called from argparse"""
|
||||
|
@ -339,10 +348,17 @@ def main_cmd(*args):
|
|||
if get_config()['DEBUG']:
|
||||
c._app.mount('/debug', DebugAPI())
|
||||
|
||||
c._app.run(server=get_config()['WSGI_SERVER'],
|
||||
server = get_config()['WSGI_SERVER']
|
||||
if server == 'pastelog':
|
||||
from paste.translogger import TransLogger
|
||||
get_config()['WSGI_SERVER_OPTIONS']['translogger_opts'] = \
|
||||
get_config()['TRANSLOGGER_OPTS']
|
||||
|
||||
c._app.run(server=server,
|
||||
host=get_config()['HOST'],
|
||||
port=get_config()['PORT'],
|
||||
debug=get_config()['DEBUG'],
|
||||
quiet=True, # this is to hide access.log style messages
|
||||
**get_config()['WSGI_SERVER_OPTIONS']
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in a new issue