fix flake8

This commit is contained in:
Yun Xu 2017-09-13 07:40:42 -07:00
parent 24bdb1ce98
commit 9c4b0f7b15
4 changed files with 59 additions and 61 deletions

View File

@ -37,8 +37,8 @@ if __name__ == "__main__":
workers=args.workers, debug=args.debug, ssl=ssl) workers=args.workers, debug=args.debug, ssl=ssl)
except ImportError as e: except ImportError as e:
logger.error("No module named {} found.\n" logger.error("No module named {} found.\n"
" Example File: project/sanic_server.py -> app\n" " Example File: project/sanic_server.py -> app\n"
" Example Module: project.sanic_server.app" " Example Module: project.sanic_server.app"
.format(e.name)) .format(e.name))
except ValueError as e: except ValueError as e:
logger.error("{}".format(e)) logger.error("{}".format(e))

View File

@ -1,7 +1,4 @@
import os import os
import sys
import syslog
import platform
import types import types

View File

@ -2,58 +2,58 @@ import logging
LOGGING_CONFIG_DEFAULTS = dict( LOGGING_CONFIG_DEFAULTS = dict(
version=1, version=1,
disable_existing_loggers=False, disable_existing_loggers=False,
loggers={ loggers={
"root": { "root": {
"level": "INFO", "level": "INFO",
"handlers": ["console"] "handlers": ["console"]
}, },
"sanic.error": { "sanic.error": {
"level": "INFO", "level": "INFO",
"handlers": ["error_console"], "handlers": ["error_console"],
"propagate": True, "propagate": True,
"qualname": "sanic.error" "qualname": "sanic.error"
}, },
"sanic.access": { "sanic.access": {
"level": "INFO", "level": "INFO",
"handlers": ["access_console"], "handlers": ["access_console"],
"propagate": True, "propagate": True,
"qualname": "sanic.access" "qualname": "sanic.access"
}
},
handlers={
"console": {
"class": "logging.StreamHandler",
"formatter": "generic",
"stream": "sys.stdout"
},
"error_console": {
"class": "logging.StreamHandler",
"formatter": "generic",
"stream": "sys.stderr"
},
"access_console": {
"class": "logging.StreamHandler",
"formatter": "access",
"stream": "sys.stdout"
},
},
formatters={
"generic": {
"format": "%(asctime)s [%(process)d] [%(levelname)s] %(message)s",
"datefmt": "[%Y-%m-%d %H:%M:%S %z]",
"class": "logging.Formatter"
},
"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 %z]",
"class": "logging.Formatter"
},
} }
},
handlers={
"console": {
"class": "logging.StreamHandler",
"formatter": "generic",
"stream": "sys.stdout"
},
"error_console": {
"class": "logging.StreamHandler",
"formatter": "generic",
"stream": "sys.stderr"
},
"access_console": {
"class": "logging.StreamHandler",
"formatter": "access",
"stream": "sys.stdout"
},
},
formatters={
"generic": {
"format": "%(asctime)s [%(process)d] [%(levelname)s] %(message)s",
"datefmt": "[%Y-%m-%d %H:%M:%S %z]",
"class": "logging.Formatter"
},
"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 %z]",
"class": "logging.Formatter"
},
}
) )

View File

@ -24,7 +24,7 @@ try:
except ImportError: except ImportError:
async_loop = asyncio async_loop = asyncio
from sanic.log import logger, access_logger, error_logger from sanic.log import logger, access_logger
from sanic.response import HTTPResponse from sanic.response import HTTPResponse
from sanic.request import Request from sanic.request import Request
from sanic.exceptions import ( from sanic.exceptions import (
@ -424,9 +424,9 @@ def serve(host, port, request_handler, error_handler, before_start=None,
request_timeout=60, ssl=None, sock=None, request_max_size=None, request_timeout=60, ssl=None, sock=None, request_max_size=None,
reuse_port=False, loop=None, protocol=HttpProtocol, backlog=100, reuse_port=False, loop=None, protocol=HttpProtocol, backlog=100,
register_sys_signals=True, run_async=False, connections=None, register_sys_signals=True, run_async=False, connections=None,
signal=Signal(), request_class=None, access_log=True, keep_alive=True, signal=Signal(), request_class=None, access_log=True,
is_request_stream=False, router=None, websocket_max_size=None, keep_alive=True, is_request_stream=False, router=None,
websocket_max_queue=None, state=None, websocket_max_size=None, websocket_max_queue=None, state=None,
graceful_shutdown_timeout=15.0): graceful_shutdown_timeout=15.0):
"""Start asynchronous HTTP Server on an individual process. """Start asynchronous HTTP Server on an individual process.
@ -519,8 +519,9 @@ def serve(host, port, request_handler, error_handler, before_start=None,
try: try:
loop.add_signal_handler(_signal, loop.stop) loop.add_signal_handler(_signal, loop.stop)
except NotImplementedError: except NotImplementedError:
logger.warn('Sanic tried to use loop.add_signal_handler but it is' logger.warn(
' not implemented on this platform.') 'Sanic tried to use loop.add_signal_handler but it is'
' not implemented on this platform.')
pid = os.getpid() pid = os.getpid()
try: try:
logger.info('Starting worker [{}]'.format(pid)) logger.info('Starting worker [{}]'.format(pid))