question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is there a way to disable message formatting ?

See original GitHub issue

Hi Delgan !

I was wondering if there was a way to disable the message formatting with the args/kwargs ?

from loguru import logger

kwargs = {"a": 1, "b": 2}
logger.info(f"Is this going to be alright ? {kwargs}", additional_infos=kwargs)

Traceback:

Traceback (most recent call last):
  File "/tmp/test.py", line 4, in <module>
    logger.info(f"Is this going to be alright ? {kwargs}", additional_infos=kwargs)
  File "/Users/gjeusel/miniconda3/envs/greenpandas/lib/python3.6/site-packages/loguru/_logger.py", line 1971, in info
    __self._log("INFO", None, False, __self._options, __message, args, kwargs)
  File "/Users/gjeusel/miniconda3/envs/greenpandas/lib/python3.6/site-packages/loguru/_logger.py", line 1948, in _log
    log_record["message"] = message.format(*args, **kwargs)
KeyError: "'a'"

Is it a feature you would be inclined in adding ? Maybe parametrized by an environment variable or via logger.configure ?

Cordially !

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:20 (7 by maintainers)

github_iconTop GitHub Comments

5reactions
Delgancommented, Sep 16, 2020

I may have some ideas to allow more freedom in configuring the message formatting. I think this feature might be of interest to some people, in your case and others. But I’m not sure of anything, we’ll see. I’ll keep this issue open in the meantime. 👍

1reaction
Delgancommented, Aug 23, 2022

@mastern2k3 You can use f-strings as long as you do not call the logging method with formatting arguments:

logger.info(f"User data: {user_data}")                      # Good.
logger.info(f"User data: {user_data}", data=user_data)      # Bad.
logger.bind(data=user_data).info(f"User data: {user_data})  # Good.

I got your point, though. I plan to remove automatic formatting in favor of f-strings.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Enable or disable full rich-text formatting in a rich text box
Right-click the rich text box for which you want to enable or disable full rich-text formatting, and then click Rich Text Box Properties...
Read more >
is there a way to disable formatting in the message bar? - Reddit
It's in the settings menu.
Read more >
How to disable plain text mode in Gmail - cloudHQ Support
Click 'Compose' in your Gmail's left navigation bar: · Click the 'More options' (three dots) in the email composition pop-up window: · Make...
Read more >
How do I turn off Slack's new format while typing?
Go to Preferences -> Advanced -> Input Options and enable Format messages with markup .
Read more >
Set your message formatting preference - Slack
Under Input Options, check or uncheck the box next to Format messages with markup. Markup. Once you've set your formatting preference, you can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found