2. aiomisc_log module#

2.1. aiomisc_log.formatter.color module#

aiomisc_log.formatter.color.color_formatter(stream: IO[str] | None = None, date_format: str | None = None, **_: Any) Handler[source]#

2.2. aiomisc_log.formatter.journald module#

aiomisc_log.formatter.journald.journald_formatter(**_: Any) Handler[source]#

2.3. aiomisc_log.formatter.json module#

class aiomisc_log.formatter.json.JSONLogFormatter(fmt: str | None = None, datefmt: str | None = None, style: ~typing.Literal['%'] | ~typing.Literal['{'] | ~typing.Literal['$'] = '%', dumps: ~typing.Callable[[~typing.Dict[str, ~typing.Any], ~typing.Any], str] = <function _dump_json>)[source]#

Bases: Formatter

Initialize the formatter with specified format strings.

Initialize the formatter either with the specified format string, or a default as described above. Allow for specialized date formatting with the optional datefmt argument. If datefmt is omitted, you get an ISO8601-like (or RFC 3339-like) format.

Use a style parameter of ‘%’, ‘{’ or ‘$’ to specify that you want to use one of %-formatting, str.format() ({}) formatting or string.Template formatting in your format string.

Changed in version 3.2: Added the style parameter.

FIELD_MAPPING = mappingproxy({'filename': ('code_file', <class 'str'>), 'funcName': ('code_func', <class 'str'>), 'lineno': ('code_line', <class 'int'>), 'module': ('code_module', <class 'str'>), 'name': ('identifier', <class 'str'>), 'msg': ('message_raw', <class 'str'>), 'process': ('pid', <class 'int'>), 'processName': ('process_name', <class 'str'>), 'threadName': ('thread_name', <class 'str'>)})#
LEVELS = mappingproxy({50: 'fatal', 40: 'error', 30: 'warn', 20: 'info', 10: 'debug', 0: None})#
format(record: LogRecord) str[source]#

Format the specified record as text.

The record’s attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string uses the time (as determined by a call to usesTime(), formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message.

formatException(exc_info: Any) str[source]#

Format and return the specified exception information as a string.

This default implementation just uses traceback.print_exception()

formatMessage(record: LogRecord) str[source]#
formatTime(record: LogRecord, datefmt: str | None = None) int | str[source]#

Return the creation time of the specified LogRecord as formatted text.

This method should be called from format() by a formatter which wants to make use of a formatted time. This method can be overridden in formatters to provide for any specific requirement, but the basic behaviour is as follows: if datefmt (a string) is specified, it is used with time.strftime() to format the creation time of the record. Otherwise, an ISO8601-like (or RFC 3339-like) format is used. The resulting string is returned. This function uses a user-configurable function to convert the creation time to a tuple. By default, time.localtime() is used; to change this for a particular formatter instance, set the ‘converter’ attribute to a function with the same signature as time.localtime() or time.gmtime(). To change it for all formatters, for example if you want all logging times to be shown in GMT, set the ‘converter’ attribute in the Formatter class.

aiomisc_log.formatter.json.json_handler(stream: IO[str] | None = None, date_format: str | None = None, **kwargs: Any) Handler[source]#

2.4. aiomisc_log.formatter.rich.py module#

aiomisc_log.formatter.rich.rich_formatter(date_format: str | None = None, stream: IO[str] | None = None, **kwargs: Any) Handler[source]#

2.5. aiomisc_log.enum module#

class aiomisc_log.enum.DateFormat(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

Bases: Enum

color = '%Y-%m-%d %H:%M:%S'#
json = '%s'#
rich = '[%X]'#
stream = '[%Y-%m-%d %H:%M:%S]'#
syslog = None#
class aiomisc_log.enum.LogFormat(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

Bases: IntEnum

classmethod choices() Tuple[str, ...][source]#
color = 1#
classmethod default() str[source]#
disabled = -1#
journald = 5#
json = 2#
plain = 4#
rich = 6#
rich_tb = 7#
stream = 0#
syslog = 3#
class aiomisc_log.enum.LogLevel(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

Bases: IntEnum

classmethod choices() Tuple[str, ...][source]#
critical = 50#
debug = 10#
classmethod default() str[source]#
error = 40#
info = 20#
notset = 0#
warning = 30#