From 8d92cd1755bea450a5cab8a511aca2e2b3650f6c Mon Sep 17 00:00:00 2001 From: Abhishek Singh Date: Thu, 14 May 2026 15:44:27 +0530 Subject: [PATCH] Fix(cli): unique per-run log filename with timestamp + mode=w (#984) --- th_cli/test_run/logging.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/th_cli/test_run/logging.py b/th_cli/test_run/logging.py index 0ad6e64..58c1938 100644 --- a/th_cli/test_run/logging.py +++ b/th_cli/test_run/logging.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import datetime import os from loguru import logger @@ -27,13 +28,22 @@ PYTHON_TEST_LEVEL = "PYTHON_TEST" logger.level(PYTHON_TEST_LEVEL, no=22, icon="🐍", color="") +_LOG_TIMESTAMP_FORMAT = "%Y-%m-%d-%H-%M-%S" def configure_logger_for_run(title: str) -> str: # Reset (Remove all sinks from logger) logger.remove() - log_path = os.path.join(config.log_config.output_log_path, f"test_run_{title}.log") - - logger.add(log_path, enqueue=True, format=config.log_config.format) + # Replace colons so the default timestamp-style title does not produce + # filenames that are invalid on Windows (e.g. when logs are shared across + # systems for triage). + safe_title = title.replace(":", "-") + timestamp = datetime.datetime.now().strftime(_LOG_TIMESTAMP_FORMAT) + log_path = os.path.join( + config.log_config.output_log_path, + f"test_run_{safe_title}_{timestamp}.log", + ) + + logger.add(log_path, enqueue=True, format=config.log_config.format, mode="w") return log_path