Как настроить HttpHandler в dict.config для отправки логов на фласк сервер

Есть вот такой код

import string

from utils import string_to_operator
import logging.config
import logging_tree

from logging_config import dict_config

logging.config.dictConfig(dict_config)


app_logger = logging.getLogger("app")
app_logger.setLevel("DEBUG")


def calc(args):
    app_logger.debug(f"Arguments: {args}")

    num_1 = args[0]
    operator = args[1]
    num_2 = args[2]

    try:
        num_1 = float(num_1)
    except ValueError as e:
        app_logger.exception(e)
        app_logger.error("Error while converting number 1")

    try:
        num_2 = float(num_2)
    except ValueError as e:
        app_logger.exception(e)
        app_logger.debug("Error while converting number 1")

    operator_func = string_to_operator(operator)

    result = operator_func(num_1, num_2)

    app_logger.debug(f"Result:  {result}")
    app_logger.debug(f"{num_1} {operator} {num_2} = {result}")


if __name__ == '__main__':
    with open("logging_tree.txt", "w") as file:
        file.write(logging_tree.format.build_description())

    calc('2+3')

Файл с конфигом

import sys
import logging.handlers
import requests


class HttpHandler(logging.handlers.HTTPHandler):
    def __init__(self, host, port, url, method='POST', headers=None, secure=False):
        super().__init__()
        self.host = host
        self.port = port
        self.url = url

    def emit(self, record: logging.LogRecord) -> None:
        address = self.host + ':' + self.port + self.url
        res = requests.post(address, data=record.__dict__)


dict_config = {
    "version": 1,
    "disable_existing_loggers": False,
    "formatters": {
        "base": {
            "format": "%(asctime)s - %(name)s - %(lineno)s - %(levelname)s - %(message)s",
        }
    },
    "handlers": {
        "screen": {
            "class": "logging.StreamHandler",
            "level": "DEBUG",
            "formatter": "base",
            "stream": sys.stdout
        },
        "file_debug": {
            "class": "logging.FileHandler",
            "level": "DEBUG",
            "formatter": "base",
            "filename": "calc_debug.log",
            "mode": "a"
        },
        "file_error": {
            "class": "logging.FileHandler",
            "level": "ERROR",
            "formatter": "base",
            "filename": "calc_error.log",
            "mode": "a"
        },
        "utils_file": {
            "class": "logging.handlers.TimedRotatingFileHandler",
            "backupCount": 5,
            "formatter": "base",
            "level": "INFO",
            "filename": "utils.log",
            "when": 'h',
            'interval': 10
        },
        "httpH": {
            "()": HttpHandler,
            "host": "127.0.0.1",
            "port": "5000",
            "url": "/log",
        }
    },
    "loggers": {
        "app": {
            "level": "DEBUG",
            "handlers": ["screen", "file_debug", "file_error", "httpH"],
        },
        "utils": {
            "level": "INFO",
            "handlers": ["screen", 'utils_file', "httpH"],
        }
    },
}

Выдает:

ValueError: Unable to configure handler 'httpH'

Не понимаю что с ним нужно сделать.


Ответы (0 шт):