Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] timefmt #3225

Open
2 tasks done
hardaker opened this issue Dec 7, 2023 · 4 comments
Open
2 tasks done

[BUG] timefmt #3225

hardaker opened this issue Dec 7, 2023 · 4 comments

Comments

@hardaker
Copy link

hardaker commented Dec 7, 2023

Describe the bug

It is impossible to use a blank datefmt ("").

import logging
from logging import debug, error, info
from rich.logging import RichHandler

logging.basicConfig(format="%(message)s",
                    handlers=[RichHandler(rich_tracebacks=True)],
                    datefmt="",
                    )

error(f"something or other")

The above forces a date:

[12/07/23 09:35:40] ERROR    something or other                                                                     test.py:10

Changing the datefmt to be a single space instead works, but adds a space to the front of the line:

                    datefmt=" ",
  ERROR    something or other                                                                                       test.py:10

Platform

Platform: linux (but shouldn't matter)

platform="Linux"
enrich==1.2.7
rich==12.5.1
rich-cli==1.8.0
rich-logging==0.0.1
rich-rst==1.1.7

Copy link

github-actions bot commented Dec 7, 2023

Thank you for your issue. Give us a little time to review it.

PS. You might want to check the FAQ if you haven't done so already.

This is an automated reply, generated by FAQtory

@hardaker
Copy link
Author

hardaker commented Dec 7, 2023

(I tried to create a patch, but failed -- not familiar enough with the internal flow handling of the date formatting)

@selmaozdere
Copy link

Hey, my university software engineering group are willing to tackle this issue. Would it be possible to assign us? Here are our git usernames @albinkempe @lolindgr @ollisco @SihamShahoud and me @selmaozdere
Thank you for your answer !!

@ollisco
Copy link

ollisco commented Feb 26, 2024

Hello @hardaker. I have found a few solutions to this issue

1. using a lambda

logging.basicConfig(format="%(message)s",
                    handlers=[RichHandler(rich_tracebacks=True)],
                    datefmt=lambda x: "", # since we can provide a Callable
                    )

2. Using a escape char

logging.basicConfig(format="%(message)s",
                    handlers=[RichHandler(rich_tracebacks=True)],
                    datefmt="\0",
                    )

3. Using the RichHandlers log_time_format property

logging.basicConfig(format="%(message)s",
                    handlers=[RichHandler(rich_tracebacks=True, log_time_format='')],
                    )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants