Skip to content

Commit f59b7ec

Browse files
committed
fix need to reset even for log output or we get interrupted by other (broken) loggers such as pytest
Signed-off-by: Qubitium <qubitium@modelcloud.ai>
1 parent 49c5163 commit f59b7ec

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

logbar/logbar.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,26 +176,26 @@ def _process(self, level: LEVEL, msg, *args, **kwargs):
176176
columns, _ = terminal_size()
177177
str_msg = str(msg)
178178

179+
if columns > 0:
180+
str_msg += " " * (columns - LEVEL_MAX_LENGTH - 2 - len(str_msg)) # -2 for cursor + space between LEVEL and msg
181+
179182
global last_pb_instance
180183
if isinstance(last_pb_instance, ProgressBar) and not last_pb_instance.closed:
181-
buf = f'\r'
182-
if columns > 0:
183-
str_msg += " " * columns
184-
185-
print(buf,end='',flush=True)
184+
print('\r',end='',flush=True)
186185

187186
# Get the color for the log level
188187

189188
reset = COLORS["RESET"]
190189
color = COLORS.get(level.value, reset)
191190

192191
level_padding = " " * (LEVEL_MAX_LENGTH - len(level.value)) # 5 is max enum string length
193-
print(f"{color}{level.value}{reset}{level_padding} {str_msg}", end='\n', flush=True)
192+
print(f"\r{color}{level.value}{reset}{level_padding} {str_msg}", end='\n', flush=True)
194193

195194
if isinstance(last_pb_instance, ProgressBar):
196195
if not last_pb_instance.closed:
197196
# only do this for our instance
198197
if self == logger:
198+
#print('\r', end='', flush=True)
199199
last_pb_instance.draw()
200200
else:
201201
last_pb_instance = None

tests/test_log.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from logbar import LogBar
44

5-
log = LogBar.shared()
5+
log = LogBar.shared(override_logger=True)
66

77
class TestProgressBar(unittest.TestCase):
88

0 commit comments

Comments
 (0)