diff --git a/sanic/app.py b/sanic/app.py index 20c02a5c..c585bf43 100644 --- a/sanic/app.py +++ b/sanic/app.py @@ -10,7 +10,7 @@ from traceback import format_exc from urllib.parse import urlencode, urlunparse from ssl import create_default_context, Purpose -from sanic.config import Config, LOGGING +from sanic.config import Config from sanic.constants import HTTP_METHODS from sanic.exceptions import ServerError, URLBuildError, SanicException from sanic.handlers import ErrorHandler @@ -28,18 +28,7 @@ class Sanic: def __init__(self, name=None, router=None, error_handler=None, load_env=True, request_class=None, - log_config=LOGGING, strict_slashes=False): - if log_config: - logging.config.dictConfig(log_config) - # Only set up a default log handler if the - # end-user application didn't set anything up. - if not logging.root.handlers and log.level == logging.NOTSET: - formatter = logging.Formatter( - "%(asctime)s: %(levelname)s: %(message)s") - handler = logging.StreamHandler() - handler.setFormatter(formatter) - log.addHandler(handler) - log.setLevel(logging.INFO) + strict_slashes=False): # Get name from previous stack frame if name is None: @@ -51,7 +40,6 @@ class Sanic: self.request_class = request_class self.error_handler = error_handler or ErrorHandler() self.config = Config(load_env=load_env) - self.log_config = log_config self.request_middleware = deque() self.response_middleware = deque() self.blueprints = {} @@ -642,7 +630,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=LOGGING): + log_config=None): """Asynchronous version of `run`. NOTE: This does not support multiprocessing and is not the preferred diff --git a/sanic/config.py b/sanic/config.py index 0c2cc701..716ec1a6 100644 --- a/sanic/config.py +++ b/sanic/config.py @@ -15,89 +15,6 @@ _address_dict = { 'FreeBSD': '/var/run/log' } -LOGGING = { - 'version': 1, - 'disable_existing_loggers': False, - 'filters': { - 'accessFilter': { - '()': DefaultFilter, - 'param': [0, 10, 20] - }, - 'errorFilter': { - '()': DefaultFilter, - 'param': [30, 40, 50] - } - }, - 'formatters': { - 'simple': { - 'format': '%(asctime)s - (%(name)s)[%(levelname)s]: %(message)s', - 'datefmt': '%Y-%m-%d %H:%M:%S' - }, - 'access': { - 'format': '%(asctime)s - (%(name)s)[%(levelname)s][%(host)s]: ' + - '%(request)s %(message)s %(status)d %(byte)d', - 'datefmt': '%Y-%m-%d %H:%M:%S' - } - }, - 'handlers': { - 'internal': { - 'class': 'logging.StreamHandler', - 'filters': ['accessFilter'], - 'formatter': 'simple', - 'stream': sys.stderr - }, - 'accessStream': { - 'class': 'logging.StreamHandler', - 'filters': ['accessFilter'], - 'formatter': 'access', - 'stream': sys.stderr - }, - 'errorStream': { - 'class': 'logging.StreamHandler', - 'filters': ['errorFilter'], - 'formatter': 'simple', - 'stream': sys.stderr - }, - # before you use accessSysLog, be sure that log levels - # 0, 10, 20 have been enabled in you syslog configuration - # otherwise you won't be able to see the output in syslog - # logging file. - 'accessSysLog': { - 'class': 'logging.handlers.SysLogHandler', - 'address': _address_dict.get(platform.system(), - ('localhost', 514)), - 'facility': syslog.LOG_DAEMON, - 'filters': ['accessFilter'], - 'formatter': 'access' - }, - 'errorSysLog': { - 'class': 'logging.handlers.SysLogHandler', - 'address': _address_dict.get(platform.system(), - ('localhost', 514)), - 'facility': syslog.LOG_DAEMON, - 'filters': ['errorFilter'], - 'formatter': 'simple' - }, - }, - 'loggers': { - 'sanic': { - 'level': 'INFO', - 'handlers': ['internal', 'errorStream'] - }, - 'network': { - 'level': 'INFO', - 'handlers': ['accessStream', 'errorStream'] - } - } -} - -# this happens when using container or systems without syslog -# keep things in config would cause file not exists error -_addr = LOGGING['handlers']['accessSysLog']['address'] -if type(_addr) is str and not os.path.exists(_addr): - LOGGING['handlers'].pop('accessSysLog') - LOGGING['handlers'].pop('errorSysLog') - class Config(dict): def __init__(self, defaults=None, load_env=True, keep_alive=True): diff --git a/sanic/log.py b/sanic/log.py index 760ad1c6..a7933c0d 100644 --- a/sanic/log.py +++ b/sanic/log.py @@ -1,18 +1,5 @@ import logging -class DefaultFilter(logging.Filter): - - def __init__(self, param=None): - self.param = param - - def filter(self, record): - if self.param is None: - return True - if record.levelno in self.param: - return True - return False - - log = logging.getLogger('sanic') netlog = logging.getLogger('network')