rich icon indicating copy to clipboard operation
rich copied to clipboard

[BUG] timefmt

Open hardaker opened this issue 1 year ago • 4 comments

  • [X] I've checked docs and closed issues for possible solutions.
  • [X] I can't find my issue in the FAQ.

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

hardaker avatar Dec 07 '23 17:12 hardaker

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

github-actions[bot] avatar Dec 07 '23 17:12 github-actions[bot]

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

hardaker avatar Dec 07 '23 17:12 hardaker

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 !!

selmaozdere avatar Feb 25 '24 12:02 selmaozdere

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='')],
                    )

ollisco avatar Feb 26 '24 19:02 ollisco