b63c06c75a
* fix the logger and make it work * modify test_logging parameters and add a new unit test
59 lines
1.6 KiB
Python
59 lines
1.6 KiB
Python
import logging
|
|
import sys
|
|
|
|
|
|
LOGGING_CONFIG_DEFAULTS = dict(
|
|
version=1,
|
|
disable_existing_loggers=False,
|
|
loggers={
|
|
"sanic.root": {"level": "INFO", "handlers": ["console"]},
|
|
"sanic.error": {
|
|
"level": "INFO",
|
|
"handlers": ["error_console"],
|
|
"propagate": True,
|
|
"qualname": "sanic.error",
|
|
},
|
|
"sanic.access": {
|
|
"level": "INFO",
|
|
"handlers": ["access_console"],
|
|
"propagate": True,
|
|
"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",
|
|
},
|
|
},
|
|
)
|
|
|
|
|
|
logger = logging.getLogger("sanic.root")
|
|
error_logger = logging.getLogger("sanic.error")
|
|
access_logger = logging.getLogger("sanic.access")
|