change to use default python config code
This commit is contained in:
50
sanic/app.py
50
sanic/app.py
@@ -2,8 +2,6 @@ import logging
|
||||
import logging.config
|
||||
import re
|
||||
import warnings
|
||||
import os
|
||||
import yaml
|
||||
from asyncio import get_event_loop, ensure_future, CancelledError
|
||||
from collections import deque, defaultdict
|
||||
from functools import partial
|
||||
@@ -12,8 +10,7 @@ from traceback import format_exc
|
||||
from urllib.parse import urlencode, urlunparse
|
||||
from ssl import create_default_context, Purpose
|
||||
|
||||
from sanic import __path__ as lib_path
|
||||
from sanic.config import Config
|
||||
from sanic.config import Config, DEFAULT_LOG_CONF
|
||||
from sanic.constants import HTTP_METHODS
|
||||
from sanic.exceptions import ServerError, URLBuildError, SanicException
|
||||
from sanic.handlers import ErrorHandler
|
||||
@@ -31,16 +28,12 @@ class Sanic:
|
||||
|
||||
def __init__(self, name=None, router=None, error_handler=None,
|
||||
load_env=True, request_class=None,
|
||||
log_config_path=os.path.join(lib_path[0], "default.conf")):
|
||||
conf = None
|
||||
if log_config_path and os.path.exists(log_config_path):
|
||||
with open(log_config_path) as f:
|
||||
conf = yaml.load(f)
|
||||
conf.setdefault('version', 1)
|
||||
logging.config.dictConfig(conf)
|
||||
# Only set up a default log handler if the
|
||||
# end-user application didn't set anything up.
|
||||
if not conf and log.level == logging.NOTSET:
|
||||
log_config=DEFAULT_LOG_CONF):
|
||||
if log_config:
|
||||
logging.config.dictConfig(log_config)
|
||||
else:
|
||||
# Only set up a default log handler if the
|
||||
# end-user application didn't set anything up.
|
||||
formatter = logging.Formatter(
|
||||
"%(asctime)s: %(levelname)s: %(message)s")
|
||||
handler = logging.StreamHandler()
|
||||
@@ -58,7 +51,7 @@ class Sanic:
|
||||
self.request_class = request_class
|
||||
self.error_handler = error_handler or ErrorHandler()
|
||||
self.config = Config(load_env=load_env)
|
||||
self.log_config_path = log_config_path
|
||||
self.log_config = log_config
|
||||
self.request_middleware = deque()
|
||||
self.response_middleware = deque()
|
||||
self.blueprints = {}
|
||||
@@ -525,7 +518,7 @@ class Sanic:
|
||||
after_start=None, before_stop=None, after_stop=None, ssl=None,
|
||||
sock=None, workers=1, loop=None, protocol=None,
|
||||
backlog=100, stop_event=None, register_sys_signals=True,
|
||||
log_config_path=os.path.join(lib_path[0], "default.yml")):
|
||||
log_config=DEFAULT_LOG_CONF):
|
||||
"""Run the HTTP Server and listen until keyboard interrupt or term
|
||||
signal. On termination, drain connections before closing.
|
||||
|
||||
@@ -552,11 +545,8 @@ class Sanic:
|
||||
:param protocol: Subclass of asyncio protocol class
|
||||
:return: Nothing
|
||||
"""
|
||||
if log_config_path and os.path.exists(log_config_path):
|
||||
with open(log_config_path) as f:
|
||||
conf = yaml.load(f)
|
||||
conf.setdefault('version', 1)
|
||||
logging.config.dictConfig(conf)
|
||||
if log_config:
|
||||
logging.config.dictConfig(log_config)
|
||||
if protocol is None:
|
||||
protocol = (WebSocketProtocol if self.websocket_enabled
|
||||
else HttpProtocol)
|
||||
@@ -571,7 +561,7 @@ class Sanic:
|
||||
after_stop=after_stop, ssl=ssl, sock=sock, workers=workers,
|
||||
loop=loop, protocol=protocol, backlog=backlog,
|
||||
register_sys_signals=register_sys_signals,
|
||||
has_log_file=log_config_path is not None)
|
||||
has_log=log_config is not None)
|
||||
|
||||
try:
|
||||
self.is_running = True
|
||||
@@ -599,18 +589,14 @@ class Sanic:
|
||||
before_stop=None, after_stop=None, ssl=None,
|
||||
sock=None, loop=None, protocol=None,
|
||||
backlog=100, stop_event=None,
|
||||
log_config_path=os.path.join(lib_path[0],
|
||||
"default.yml")):
|
||||
log_config=DEFAULT_LOG_CONF):
|
||||
"""Asynchronous version of `run`.
|
||||
|
||||
NOTE: This does not support multiprocessing and is not the preferred
|
||||
way to run a Sanic application.
|
||||
"""
|
||||
if log_config_path and os.path.exists(log_config_path):
|
||||
with open(log_config_path) as f:
|
||||
conf = yaml.load(f)
|
||||
conf.setdefault('version', 1)
|
||||
logging.config.dictConfig(conf)
|
||||
if log_config:
|
||||
logging.config.dictConfig(log_config)
|
||||
if protocol is None:
|
||||
protocol = (WebSocketProtocol if self.websocket_enabled
|
||||
else HttpProtocol)
|
||||
@@ -625,7 +611,7 @@ class Sanic:
|
||||
after_stop=after_stop, ssl=ssl, sock=sock,
|
||||
loop=loop or get_event_loop(), protocol=protocol,
|
||||
backlog=backlog, run_async=True,
|
||||
has_log_file=log_config_path is not None)
|
||||
has_log=log_config is not None)
|
||||
|
||||
return await serve(**server_settings)
|
||||
|
||||
@@ -655,7 +641,7 @@ class Sanic:
|
||||
before_start=None, after_start=None, before_stop=None,
|
||||
after_stop=None, ssl=None, sock=None, workers=1, loop=None,
|
||||
protocol=HttpProtocol, backlog=100, stop_event=None,
|
||||
register_sys_signals=True, run_async=False, has_log_file=True):
|
||||
register_sys_signals=True, run_async=False, has_log=True):
|
||||
"""Helper function used by `run` and `create_server`."""
|
||||
|
||||
if isinstance(ssl, dict):
|
||||
@@ -708,7 +694,7 @@ class Sanic:
|
||||
'loop': loop,
|
||||
'register_sys_signals': register_sys_signals,
|
||||
'backlog': backlog,
|
||||
'has_log_file': has_log_file
|
||||
'has_log': has_log
|
||||
}
|
||||
|
||||
# -------------------------------------------- #
|
||||
|
||||
Reference in New Issue
Block a user