Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion torchx/cli/cmd_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def print_log_lines(
streams=streams,
):
prefix = f"{GREEN}{role_name}/{replica_id}{ENDC} "
print(_prefix_line(prefix, line), file=file, end="", flush=True)
print(_prefix_line(prefix, line.strip()), file=file, end="\n", flush=True)
except Exception as e:
exceptions.put(e)
raise
Expand Down
8 changes: 8 additions & 0 deletions torchx/cli/test/cmd_log_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,11 @@ def test_prefix_line(self) -> None:
self.assertEqual(
_prefix_line("<prefix>", "foo\ntest\n"), "<prefix>foo\n<prefix>test\n"
)

def test_prefix_line_with_timestamp(self) -> None:
# Test that stripping and prefixing works correctly with timestamp logs
log_with_timestamp = "2024-01-01T10:00:00.123Z [INFO] - Test message\n"
result = _prefix_line("role/0 ", log_with_timestamp.strip())
self.assertEqual(
result, "role/0 2024-01-01T10:00:00.123Z [INFO] - Test message"
)
Loading