MCPcopy Create free account
hub / github.com/FastMAS/KVCOMM / initialize_log_file

Function initialize_log_file

KVCOMM/utils/log.py:28–47  ·  view source on GitHub ↗

Initialize the log file with a start message and return its path. Args: mode (str): The mode of operation, used in the file path. time_stamp (str): The current timestamp, used in the file path. Returns: Path: The path to the initialized log file.

(experiment_name: str, time_stamp: str)

Source from the content-addressed store, hash-verified

26 logger.add(target_path, level=logfile_level, rotation="10 MB")
27
28def initialize_log_file(experiment_name: str, time_stamp: str) -> Path:
29 """
30 Initialize the log file with a start message and return its path.
31
32 Args:
33 mode (str): The mode of operation, used in the file path.
34 time_stamp (str): The current timestamp, used in the file path.
35
36 Returns:
37 Path: The path to the initialized log file.
38 """
39 try:
40 log_file_path = KVCOMM_ROOT / f'result/{experiment_name}/logs/log_{time_stamp}.txt'
41 os.makedirs(log_file_path.parent, exist_ok=True)
42 with open(log_file_path, 'w') as file:
43 file.write("============ Start ============\n")
44 except OSError as error:
45 logger.error(f"Error initializing log file: {error}")
46 raise
47 return log_file_path
48
49def swarmlog(sender: str, text: str, cost: float, prompt_tokens: int, complete_tokens: int, log_file_path: str) -> None:
50 """

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected