Skip to content

Настройки логирования

Bases: BaseModel

Logging Settings.

Examples

Using json preset:

.. code-block:: bash

HORIZON__SERVER__LOGGING__SETUP=True
HORIZON__SERVER__LOGGING__PRESET=json

Passing custom logging config file:

.. code-block:: bash

HORIZON__SERVER__LOGGING__SETUP=True
HORIZON__SERVER__LOGGING__CUSTOM_CONFIG_PATH=/some/logging.yml

Setup logging in some other way, e.g. using uvicorn args <https://www.uvicorn.org/settings/#logging>_:

.. code-block:: bash

$ export HORIZON__SERVER__LOGGING__SETUP=False
$ python -m horizon.backend --log-level debug
Source code in horizon/backend/settings/server/log/__init__.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
class LoggingSettings(BaseModel):
    """Logging Settings.

    Examples
    --------

    Using ``json`` preset:

    .. code-block:: bash

        HORIZON__SERVER__LOGGING__SETUP=True
        HORIZON__SERVER__LOGGING__PRESET=json

    Passing custom logging config file:

    .. code-block:: bash

        HORIZON__SERVER__LOGGING__SETUP=True
        HORIZON__SERVER__LOGGING__CUSTOM_CONFIG_PATH=/some/logging.yml

    Setup logging in some other way, e.g. using `uvicorn args <https://www.uvicorn.org/settings/#logging>`_:

    .. code-block:: bash

        $ export HORIZON__SERVER__LOGGING__SETUP=False
        $ python -m horizon.backend --log-level debug
    """

    setup: bool = Field(
        default=True,
        description="If ``True``, setup logging during application start",
    )
    preset: Literal["json", "plain", "colored"] = Field(
        default="plain",
        description=textwrap.dedent(
            """
            Name of logging preset to use.

            There are few logging presets bundled to ``data-horizon[backend]`` package:

            .. dropdown:: ``plain`` preset

                This preset is recommended to use in environment which do not support colored output,
                e.g. CI jobs

                .. literalinclude:: ../../../horizon/backend/settings/server/log/plain.yml

            .. dropdown:: ``colored`` preset

                This preset is recommended to use in development environment,
                as it simplifies debugging. Each log record is output with color specific for a log level

                .. literalinclude:: ../../../horizon/backend/settings/server/log/colored.yml

            .. dropdown:: ``json`` preset

                This preset is recommended to use in production environment,
                as it allows to avoid writing complex log parsing configs. Each log record is output as JSON line

                .. literalinclude:: ../../../horizon/backend/settings/server/log/json.yml
            """,
        ),
    )

    custom_config_path: Optional[Path] = Field(
        default=None,
        description=textwrap.dedent(
            """
            Path to custom logging configuration file. If set, overrides :obj:`~preset` value.

            File content should be in YAML format and conform
            `logging.dictConfig <https://docs.python.org/3/library/logging.config.html#logging-config-dictschema>`_.
            """,
        ),
    )

    def get_log_config_path(self) -> Path:
        return self.custom_config_path or LOG_PATH / f"{self.preset}.yml"