Skip to content

formatter created with logging.Formatter caused ValueError and RecursionError #51

Description

@Karmenzind

My setup code:

    loki_handler = LokiLoggerHandler(
        url=LOKI_ADDR + "/loki/api/v1/push",
        labels={"service_name": PROJECT_NAME},
        label_keys={"level": "level"},
        timeout=10,
        enable_self_errors=True,
    )
    loki_handler.setFormatter(logging.Formatter(plain_fmt))

According to the README, logging.Formatter is supposed to be supportted, but it actually isn't. Here's the error I encountered:

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/loki_logger_handler/loki_logger_handler.py", line 103, in emit
    formatted_record, log_loki_metadata = self.formatter.format(record)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: too many values to unpack (expected 2)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/loki_logger_handler/loki_logger_handler.py", line 103, in emit
    formatted_record, log_loki_metadata = self.formatter.format(record)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: too many values to unpack (expected 2)

During handling of the above exception, another exception occurred:

(...and many duplicated logs...)

Seems that the recursive errors are due to enable_self_errors=True

In the source code of logging, logging.Formatter only returns 1 value:

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions