Utility

sanic.compat

class sanic.compat.Header

Bases: CIMultiDict

Container used for both request and response headers. It is a subclass of CIMultiDict.

It allows for multiple values for a single key in keeping with the HTTP spec. Also, all keys are case in-sensitive.

Please checkout the MultiDict documentation for more details about how to use the object. In general, it should work very similar to a regular dictionary.

get_all(key)

Convenience method mapped to getall().

Parameters

key (str) –

sanic.log

enum sanic.log.Colors(value)

Bases: str, Enum

An enumeration.

Member Type

str

Valid values are as follows:

END = <Colors.END: '\x1b[0m'>
BLUE = <Colors.BLUE: '\x1b[01;34m'>
GREEN = <Colors.GREEN: '\x1b[01;32m'>
PURPLE = <Colors.PURPLE: '\x1b[01;35m'>
RED = <Colors.RED: '\x1b[01;31m'>
SANIC = <Colors.SANIC: '\x1b[38;2;255;13;104m'>
YELLOW = <Colors.YELLOW: '\x1b[01;33m'>
class sanic.log.VerbosityFilter(name='')

Bases: Filter

filter(record)

Determine if the specified record is to be logged.

Is the specified record to be logged? Returns 0 for no, nonzero for yes. If deemed appropriate, the record may be modified in-place.

Parameters

record (LogRecord) –

Return type

bool

sanic.log.LOGGING_CONFIG_DEFAULTS: Dict[str, Any] = {'disable_existing_loggers': False, 'formatters': {'access': {'class': 'logging.Formatter', 'datefmt': '[%Y-%m-%d %H:%M:%S %z]', 'format': '%(asctime)s - (%(name)s)[%(levelname)s][%(host)s]: %(request)s %(message)s %(status)d %(byte)d'}, 'generic': {'class': 'logging.Formatter', 'datefmt': '[%Y-%m-%d %H:%M:%S %z]', 'format': '%(asctime)s [%(process)d] [%(levelname)s] %(message)s'}}, 'handlers': {'access_console': {'class': 'logging.StreamHandler', 'formatter': 'access', 'stream': <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>}, 'console': {'class': 'logging.StreamHandler', 'formatter': 'generic', 'stream': <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>}, 'error_console': {'class': 'logging.StreamHandler', 'formatter': 'generic', 'stream': <_io.TextIOWrapper name='<stderr>' mode='w' encoding='utf-8'>}}, 'loggers': {'sanic.access': {'handlers': ['access_console'], 'level': 'INFO', 'propagate': True, 'qualname': 'sanic.access'}, 'sanic.error': {'handlers': ['error_console'], 'level': 'INFO', 'propagate': True, 'qualname': 'sanic.error'}, 'sanic.root': {'handlers': ['console'], 'level': 'INFO'}}, 'version': 1}

Defult logging configuration

sanic.log.access_logger = <Logger sanic.access (WARNING)>

Logger used by Sanic for access logging

sanic.log.error_logger = <Logger sanic.error (WARNING)>

Logger used by Sanic for error logging

sanic.log.logger = <Logger sanic.root (WARNING)>

General Sanic logger