Skip to content

Commit

Permalink
Show chunks.
Browse files Browse the repository at this point in the history
  • Loading branch information
marrobi committed Oct 10, 2024
1 parent 92abbe8 commit e269f86
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion resource_processor/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.9.1"
__version__ = "0.9.1"
7 changes: 5 additions & 2 deletions resource_processor/shared/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,13 @@ def initialize_logging() -> logging.Logger:

def chunk_log_output(output: str, chunk_size: int = 30000):
"""
Split the log output into smaller chunks.
Split the log output into smaller chunks and prefix each chunk with [Log chunk X of Y].
"""
total_chunks = (len(output) + chunk_size - 1) // chunk_size # Calculate total number of chunks
for i in range(0, len(output), chunk_size):
yield output[i:i + chunk_size]
current_chunk = i // chunk_size + 1
prefix = f"[Log chunk {current_chunk} of {total_chunks}] "
yield prefix + output[i:i + chunk_size]


def shell_output_logger(console_output: str, prefix_item: str, logging_level: int):
Expand Down
8 changes: 4 additions & 4 deletions resource_processor/tests_rp/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ def test_shell_output_logger_chunked_logging(mock_logger):
console_output = "A" * 60000 # 60,000 characters long
shell_output_logger(console_output, "prefix", logging.DEBUG)
assert mock_logger.log.call_count == 2
mock_logger.log.assert_any_call(logging.DEBUG, f"prefix {'A' * 30000}")
mock_logger.log.assert_any_call(logging.DEBUG, f"prefix {'A' * 30000}")
mock_logger.log.assert_any_call(logging.DEBUG, f"prefix [Log chunk 1 of 2] {'A' * 30000}")
mock_logger.log.assert_any_call(logging.DEBUG, f"prefix [Log chunk 2 of 2] {'A' * 30000}")


def test_chunk_log_output():
output = "A" * 60000 # 60,000 characters long
chunks = list(chunk_log_output(output, chunk_size=30000))
assert len(chunks) == 2
assert chunks[0] == "A" * 30000
assert chunks[1] == "A" * 30000
assert chunks[0] == "[Log chunk 1 of 2] " + "A" * 30000
assert chunks[1] == "[Log chunk 2 of 2] " + "A" * 30000

0 comments on commit e269f86

Please sign in to comment.