Commit b658ff2d authored by Karoline Pauls's avatar Karoline Pauls 🐺
Browse files

small doc changes

parent 48eabf9f
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@ if os.environ.get("DEBUG"):
    handler.formatter = StructuredFormatter(
        structured_formatter_config=StructuredFormatterConfig(
            dumps_fn=make_friendly_dump_fn(
                # Enable colours only if the handler pointed to a teletype.
                # Enable colours only if the handler is pointed to a teletype.
                colours=isinstance(handler, logging.StreamHandler) and handler.stream.isatty()
            ),
        )
+15 −8
Original line number Diff line number Diff line
@@ -253,7 +253,7 @@ You can modify the current context with `add_context <logstruct.add_context>`, `
   {..., "message": "no context"}

Modifications only apply to the current scope. Once the scope ends, all
modifications are lost.
modifications are rolled back.

.. testcode::

@@ -271,6 +271,9 @@ modifications are lost.
Configuration
-------------

Configuration, including `logging.config.fileConfig` and `logging.config.dictConfig`, works just like it does
in the standard library, allowing to set up stdlib logging and ``logstruct`` in one go.

.. _logger_config:

Logger configuration
@@ -280,20 +283,22 @@ There is no configuration specific to `StructuredLogger`. Since each `Structured
with a `logging.Logger` with the same name, that logger should be configured as in the `official
docs <https://docs.python.org/3/library/logging.config.html#module-logging.config>`_.

`logging.config.fileConfig` and `logging.config.dictConfig` configuration works just like it does in
the standard library.

.. _formatter_usage:
.. _formatter_configuration:

Formatter configuration
^^^^^^^^^^^^^^^^^^^^^^^

A `StructuredFormatter` is configured using `StructuredFormatterConfig`.
A `StructuredFormatter` is configured using `StructuredFormatterConfig`. It can be either supplied directly
via the ``structured_formatter_config`` argument to `StructuredFormatter` or loaded from data.


Logstruct provides two default configs: `logstruct.CONFIG_FORMATTED_MESSAGE` and
`logstruct.CONFIG_RAW_MESSAGE`, which can be used directly or copied to derive custom configuration.

`StructuredFormatterConfig` reference
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. list-table:: `StructuredFormatterConfig` attributes
    :header-rows: 1

@@ -309,7 +314,7 @@ Logstruct provides two default configs: `logstruct.CONFIG_FORMATTED_MESSAGE` and

    *   - `uses_time <StructuredFormatterConfig.uses_time>`
        - ``True``
        - Determines if the current time should be assigned to ``LogRecord.asctime``.
        - Determines if current time should be assigned to ``LogRecord.asctime``.

    *   - `log_fields <StructuredFormatterConfig.log_fields>`
        - `DEFAULT_LOG_FIELDS`
@@ -386,8 +391,10 @@ attribute is missing or evaluates to False.
    {"task": null}


Highly customised configuration example
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. _highly-customised-configuration-example:

`StructuredFormatterConfig` example
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The following example defines completely custom configuration, featuring: