Skip to content

There is an exception problem when printing brace using f-string #1210

Open
@yuanlongliao

Description

@yuanlongliao
from loguru import logger
LOG_FORMAT = "{time:YYYY-MM-DD HH:mm:ss.SSS} | {level} | {extra} | {message}"
logger.remove()
logger.add(sys.stdout, format=LOG_FORMAT)
logger.info(f"{'{'}", e = "extra1")

When a string with '{' or '}' characters is printed in f-string format and the extra parameter is included, the following exception will be thrown

exception:

Traceback (most recent call last):
  File "/home/unitx/unitx_repos/util/util/log_test.py", line 114, in <module>
    logger.info(f"{'{'}", e = "extra1")
  File "/home/unitx/miniconda3/envs/unified_dev/lib/python3.11/site-packages/loguru/_logger.py", line 2044, in info
    __self._log("INFO", False, __self._options, __message, args, kwargs)
  File "/home/unitx/miniconda3/envs/unified_dev/lib/python3.11/site-packages/loguru/_logger.py", line 2021, in _log
    log_record["message"] = message.format(*args, **kwargs)
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: Single '{' encountered in format string

I have observed that other people have also encountered this problem before, may I ask whether this problem has been fixed? I switched to loguru from another library, so it's not practical to change it line by line

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions