use access_log as param
This commit is contained in:
parent
c9a40c180a
commit
c9cbc00e36
17
sanic/app.py
17
sanic/app.py
|
@ -567,7 +567,7 @@ class Sanic:
|
|||
def run(self, host=None, port=None, debug=False, ssl=None,
|
||||
sock=None, workers=1, protocol=None,
|
||||
backlog=100, stop_event=None, register_sys_signals=True,
|
||||
log_config=None):
|
||||
access_log=True):
|
||||
"""Run the HTTP Server and listen until keyboard interrupt or term
|
||||
signal. On termination, drain connections before closing.
|
||||
|
||||
|
@ -588,9 +588,6 @@ class Sanic:
|
|||
if sock is None:
|
||||
host, port = host or "127.0.0.1", port or 8000
|
||||
|
||||
if log_config:
|
||||
self.log_config = log_config
|
||||
logging.config.dictConfig(log_config)
|
||||
if protocol is None:
|
||||
protocol = (WebSocketProtocol if self.websocket_enabled
|
||||
else HttpProtocol)
|
||||
|
@ -603,7 +600,7 @@ class Sanic:
|
|||
host=host, port=port, debug=debug, ssl=ssl, sock=sock,
|
||||
workers=workers, protocol=protocol, backlog=backlog,
|
||||
register_sys_signals=register_sys_signals,
|
||||
has_log=self.log_config is not None)
|
||||
access_log=access_log)
|
||||
|
||||
try:
|
||||
self.is_running = True
|
||||
|
@ -630,7 +627,7 @@ class Sanic:
|
|||
async def create_server(self, host=None, port=None, debug=False,
|
||||
ssl=None, sock=None, protocol=None,
|
||||
backlog=100, stop_event=None,
|
||||
log_config=None):
|
||||
access_log=True):
|
||||
"""Asynchronous version of `run`.
|
||||
|
||||
NOTE: This does not support multiprocessing and is not the preferred
|
||||
|
@ -639,8 +636,6 @@ class Sanic:
|
|||
if sock is None:
|
||||
host, port = host or "127.0.0.1", port or 8000
|
||||
|
||||
if log_config:
|
||||
logging.config.dictConfig(log_config)
|
||||
if protocol is None:
|
||||
protocol = (WebSocketProtocol if self.websocket_enabled
|
||||
else HttpProtocol)
|
||||
|
@ -654,7 +649,7 @@ class Sanic:
|
|||
host=host, port=port, debug=debug, ssl=ssl, sock=sock,
|
||||
loop=get_event_loop(), protocol=protocol,
|
||||
backlog=backlog, run_async=True,
|
||||
has_log=log_config is not None)
|
||||
access_log=access_log)
|
||||
|
||||
# Trigger before_start events
|
||||
await self.trigger_events(
|
||||
|
@ -699,7 +694,7 @@ class Sanic:
|
|||
def _helper(self, host=None, port=None, debug=False,
|
||||
ssl=None, sock=None, workers=1, loop=None,
|
||||
protocol=HttpProtocol, backlog=100, stop_event=None,
|
||||
register_sys_signals=True, run_async=False, has_log=True):
|
||||
register_sys_signals=True, run_async=False, access_log=True):
|
||||
"""Helper function used by `run` and `create_server`."""
|
||||
if isinstance(ssl, dict):
|
||||
# try common aliaseses
|
||||
|
@ -738,7 +733,7 @@ class Sanic:
|
|||
'loop': loop,
|
||||
'register_sys_signals': register_sys_signals,
|
||||
'backlog': backlog,
|
||||
'has_log': has_log,
|
||||
'access_log': access_log,
|
||||
'websocket_max_size': self.config.WEBSOCKET_MAX_SIZE,
|
||||
'websocket_max_queue': self.config.WEBSOCKET_MAX_QUEUE,
|
||||
'graceful_shutdown_timeout': self.config.GRACEFUL_SHUTDOWN_TIMEOUT
|
||||
|
|
|
@ -65,15 +65,15 @@ class HttpProtocol(asyncio.Protocol):
|
|||
# request config
|
||||
'request_handler', 'request_timeout', 'request_max_size',
|
||||
'request_class', 'is_request_stream', 'router',
|
||||
# enable or disable access log / error log purpose
|
||||
'has_log',
|
||||
# enable or disable access log purpose
|
||||
'access_log',
|
||||
# connection management
|
||||
'_total_request_size', '_timeout_handler', '_last_communication_time',
|
||||
'_is_stream_handler')
|
||||
|
||||
def __init__(self, *, loop, request_handler, error_handler,
|
||||
signal=Signal(), connections=set(), request_timeout=60,
|
||||
request_max_size=None, request_class=None, has_log=True,
|
||||
request_max_size=None, request_class=None, access_log=True,
|
||||
keep_alive=True, is_request_stream=False, router=None,
|
||||
state=None, debug=False, **kwargs):
|
||||
self.loop = loop
|
||||
|
@ -84,7 +84,7 @@ class HttpProtocol(asyncio.Protocol):
|
|||
self.headers = None
|
||||
self.router = router
|
||||
self.signal = signal
|
||||
self.has_log = has_log
|
||||
self.access_log = access_log
|
||||
self.connections = connections
|
||||
self.request_handler = request_handler
|
||||
self.error_handler = error_handler
|
||||
|
@ -246,7 +246,7 @@ class HttpProtocol(asyncio.Protocol):
|
|||
response.output(
|
||||
self.request.version, keep_alive,
|
||||
self.request_timeout))
|
||||
if self.has_log:
|
||||
if self.access_log:
|
||||
netlog.info('', extra={
|
||||
'status': response.status,
|
||||
'byte': len(response.body),
|
||||
|
@ -288,7 +288,7 @@ class HttpProtocol(asyncio.Protocol):
|
|||
response.transport = self.transport
|
||||
await response.stream(
|
||||
self.request.version, keep_alive, self.request_timeout)
|
||||
if self.has_log:
|
||||
if self.access_log:
|
||||
netlog.info('', extra={
|
||||
'status': response.status,
|
||||
'byte': -1,
|
||||
|
@ -333,7 +333,7 @@ class HttpProtocol(asyncio.Protocol):
|
|||
"Writing error failed, connection closed {}".format(repr(e)),
|
||||
from_error=True)
|
||||
finally:
|
||||
if self.has_log:
|
||||
if self.access_log:
|
||||
extra = dict()
|
||||
if isinstance(response, HTTPResponse):
|
||||
extra['status'] = response.status
|
||||
|
@ -424,7 +424,7 @@ def serve(host, port, request_handler, error_handler, before_start=None,
|
|||
request_timeout=60, ssl=None, sock=None, request_max_size=None,
|
||||
reuse_port=False, loop=None, protocol=HttpProtocol, backlog=100,
|
||||
register_sys_signals=True, run_async=False, connections=None,
|
||||
signal=Signal(), request_class=None, has_log=True, keep_alive=True,
|
||||
signal=Signal(), request_class=None, access_log=True, keep_alive=True,
|
||||
is_request_stream=False, router=None, websocket_max_size=None,
|
||||
websocket_max_queue=None, state=None,
|
||||
graceful_shutdown_timeout=15.0):
|
||||
|
@ -453,7 +453,7 @@ def serve(host, port, request_handler, error_handler, before_start=None,
|
|||
:param loop: asyncio compatible event loop
|
||||
:param protocol: subclass of asyncio protocol class
|
||||
:param request_class: Request class to use
|
||||
:param has_log: disable/enable access log and error log
|
||||
:param access_log: disable/enable access log
|
||||
:param is_request_stream: disable/enable Request.stream
|
||||
:param router: Router object
|
||||
:return: Nothing
|
||||
|
@ -476,7 +476,7 @@ def serve(host, port, request_handler, error_handler, before_start=None,
|
|||
request_timeout=request_timeout,
|
||||
request_max_size=request_max_size,
|
||||
request_class=request_class,
|
||||
has_log=has_log,
|
||||
access_log=access_log,
|
||||
keep_alive=keep_alive,
|
||||
is_request_stream=is_request_stream,
|
||||
router=router,
|
||||
|
|
Loading…
Reference in New Issue
Block a user