Skip to content

Commit 5bebc17

Browse files
committed
removed requirement to add space to time format in log
1 parent c13cbfd commit 5bebc17

File tree

6 files changed

+11
-11
lines changed

6 files changed

+11
-11
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "rich"
33
homepage = "https://github.com/willmcgugan/rich"
44
documentation = "https://rich.readthedocs.io/en/latest/"
5-
version = "1.1.1"
5+
version = "1.1.2"
66
description = "Render rich text, tables, progress bars, syntax highlighting, markdown and more to the terminal"
77
authors = ["Will McGugan <willmcgugan@gmail.com>"]
88
license = "MIT"

rich/_log_render.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def __init__(
1414
show_time: bool = True,
1515
show_level: bool = False,
1616
show_path: bool = True,
17-
time_format: str = "[%x %X] ",
17+
time_format: str = "[%x %X]",
1818
) -> None:
1919
self.show_time = show_time
2020
self.show_level = show_level
@@ -35,11 +35,11 @@ def __call__(
3535
from .containers import Renderables
3636
from .table import Table
3737

38-
output = Table(show_header=False, expand=True, box=None, padding=0)
38+
output = Table(show_header=False, expand=True, box=None, padding=(0, 1, 0, 0))
3939
if self.show_time:
4040
output.add_column(style="log.time")
4141
if self.show_level:
42-
output.add_column(style="log.level", width=9)
42+
output.add_column(style="log.level", width=8)
4343
output.add_column(ratio=1, style="log.message")
4444
if self.show_path and path:
4545
output.add_column(style="log.path")
@@ -57,7 +57,7 @@ def __call__(
5757
row.append(level)
5858
row.append(Renderables(renderables))
5959
if self.show_path and path:
60-
row.append(Text(f"{path}:{line_no}" if line_no else path))
60+
row.append(Text(f" {path}:{line_no}" if line_no else path))
6161

6262
output.add_row(*row)
6363
return output

rich/console.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ def __init__(
259259
highlight: bool = True,
260260
log_time: bool = True,
261261
log_path: bool = True,
262-
log_time_format: str = "[%X] ",
262+
log_time_format: str = "[%X]",
263263
highlighter: Optional["HighlighterType"] = ReprHighlighter(),
264264
):
265265
self._styles = themes.DEFAULT.styles if theme is None else theme.styles

rich/logging.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def emit(self, record: LogRecord) -> None:
6262
FORMAT = "%(message)s"
6363
# FORMAT = "%(asctime)-15s - %(level) - %(message)s"
6464
logging.basicConfig(
65-
level="NOTSET", format=FORMAT, datefmt="[%X] ", handlers=[RichHandler()]
65+
level="NOTSET", format=FORMAT, datefmt="[%X]", handlers=[RichHandler()]
6666
)
6767
log = logging.getLogger("rich")
6868

tests/test_log.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def render_log():
1313
file=io.StringIO(),
1414
width=80,
1515
force_terminal=True,
16-
log_time_format="[TIME] ",
16+
log_time_format="[TIME]",
1717
color_system="truecolor",
1818
)
1919
console.log()
@@ -23,7 +23,7 @@ def render_log():
2323

2424

2525
def test_log():
26-
expected = "\n\x1b[2;36m[TIME] \x1b[0mHello from \x1b[1m<\x1b[0m\x1b[1;38;5;13mconsole\x1b[0m\x1b[39m \x1b[0m\x1b[3;33mwidth\x1b[0m\x1b[39m=\x1b[0m\x1b[1;34m80\x1b[0m\x1b[39m ColorSystem.TRUECOLOR\x1b[0m\x1b[1m>\x1b[0m ! \x1b[2mtest_log.py:20\x1b[0m\n\x1b[2;36m \x1b[0m\x1b[1m[\x1b[0m\x1b[1;34m1\x1b[0m, \x1b[1;34m2\x1b[0m, \x1b[1;34m3\x1b[0m\x1b[1m]\x1b[0m \x1b[2mtest_log.py:21\x1b[0m\n \x1b[3m Locals \x1b[0m \n \x1b[34m╭─────────┬────────────────────────────────────────╮\x1b[0m \n \x1b[34m│\x1b[0m\x1b[32m'console'\x1b[0m\x1b[34m│\x1b[0m\x1b[1m<\x1b[0m\x1b[1;38;5;13mconsole\x1b[0m\x1b[39m \x1b[0m\x1b[3;33mwidth\x1b[0m\x1b[39m=\x1b[0m\x1b[1;34m80\x1b[0m\x1b[39m ColorSystem.TRUECOLOR\x1b[0m\x1b[1m>\x1b[0m\x1b[34m│\x1b[0m \n \x1b[34m╰─────────┴────────────────────────────────────────╯\x1b[0m \n"
26+
expected = "\n\x1b[2;36m[TIME]\x1b[0m\x1b[2;36m \x1b[0mHello from \x1b[1m<\x1b[0m\x1b[1;38;5;13mconsole\x1b[0m\x1b[39m \x1b[0m\x1b[3;33mwidth\x1b[0m\x1b[39m=\x1b[0m\x1b[1;34m80\x1b[0m\x1b[39m ColorSystem.TRUECOLOR\x1b[0m\x1b[1m>\x1b[0m ! \x1b[2m test_log.py:20\x1b[0m\x1b[2m \x1b[0m\n\x1b[2;36m \x1b[0m\x1b[2;36m \x1b[0m\x1b[1m[\x1b[0m\x1b[1;34m1\x1b[0m, \x1b[1;34m2\x1b[0m, \x1b[1;34m3\x1b[0m\x1b[1m]\x1b[0m \x1b[2m test_log.py:21\x1b[0m\x1b[2m \x1b[0m\n \x1b[3m Locals \x1b[0m \n \x1b[34m╭─────────┬────────────────────────────────────────╮\x1b[0m \n \x1b[34m│\x1b[0m\x1b[32m'console'\x1b[0m\x1b[34m│\x1b[0m\x1b[1m<\x1b[0m\x1b[1;38;5;13mconsole\x1b[0m\x1b[39m \x1b[0m\x1b[3;33mwidth\x1b[0m\x1b[39m=\x1b[0m\x1b[1;34m80\x1b[0m\x1b[39m ColorSystem.TRUECOLOR\x1b[0m\x1b[1m>\x1b[0m\x1b[34m│\x1b[0m \n \x1b[34m╰─────────┴────────────────────────────────────────╯\x1b[0m \n"
2727
assert render_log() == expected
2828

2929

tests/test_logging.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
console=Console(file=io.StringIO(), force_terminal=True, width=80)
99
)
1010
logging.basicConfig(
11-
level="NOTSET", format="%(message)s", datefmt="[DATE] ", handlers=[handler]
11+
level="NOTSET", format="%(message)s", datefmt="[DATE]", handlers=[handler]
1212
)
1313
log = logging.getLogger("rich")
1414

@@ -21,7 +21,7 @@ def make_log():
2121

2222
def test_log():
2323
render = make_log()
24-
expected = "\x1b[2;36m[DATE] \x1b[0m\x1b[32mDEBUG\x1b[0m foo \x1b[2mtest_logging.py:17\x1b[0m\n"
24+
expected = "\x1b[2;36m[DATE]\x1b[0m\x1b[2;36m \x1b[0m\x1b[32mDEBUG\x1b[0m foo \x1b[2m test_logging.py:17\x1b[0m\x1b[2m \x1b[0m\n"
2525
assert render == expected
2626

2727

0 commit comments

Comments
 (0)