Skip to content

Commit f28c3c5

Browse files
author
henrique
committed
refactor cli logger
1 parent 7fe4ee4 commit f28c3c5

2 files changed

Lines changed: 16 additions & 9 deletions

File tree

src/codeevolve/utils/cli_setup.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,11 @@ def setup_island_args(
316316
# ---------------------------------------------------------------------------
317317

318318

319-
def print_dict_rec(base_dict: Dict[str, Any], forbidden_keys: Optional[List[str]] = None) -> None:
319+
def print_dict_rec(
320+
base_dict: Dict[str, Any],
321+
forbidden_keys: Optional[List[str]] = None,
322+
indent: int = 0,
323+
) -> None:
320324
"""Recursively prints a dictionary in a formatted hierarchical structure.
321325
322326
For nested dictionaries, prints a header with the key name surrounded by
@@ -328,17 +332,18 @@ def print_dict_rec(base_dict: Dict[str, Any], forbidden_keys: Optional[List[str]
328332
dictionaries will be recursively printed with indentation headers.
329333
forbidden_keys: List of forbidden keys that will not be printed.
330334
Recursively passed to nested dicts.
335+
indent: Auxiliary integer for indentation.
331336
"""
337+
prefix: str = " " * indent
332338
for key, value in base_dict.items():
333339
if isinstance(value, dict):
334-
print(f" === {key} START ===")
335-
print_dict_rec(value, forbidden_keys)
336-
print(f" === {key} END ===")
340+
print(f"{prefix}{key}:")
341+
print_dict_rec(value, forbidden_keys, indent + 1)
337342
else:
338343
if forbidden_keys is None or key not in forbidden_keys:
339-
print(f"{key}:{value}")
344+
print(f"{prefix}{key}: {value}")
340345
else:
341-
print(f"{key}:***")
346+
print(f"{prefix}{key}: ***")
342347

343348

344349
def display_run_data(

src/codeevolve/utils/logging.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,14 @@ def _print_global_status(args: Dict[str, Any], global_data: GlobalSyncData) -> N
250250
elapsed_str: str = format_elapsed_time(elapsed)
251251
print("=" * 100)
252252
print(ASCII_NAME)
253-
print("=" * 100)
254-
print("=" * 46 + " STATUS " + "=" * 46)
255-
print(f"> ELAPSED TIME = {elapsed_str}")
253+
print("=" * 46 + " INFO " + "=" * 46)
256254
print(f"> CPU COUNT = {global_data.cpu_count.value}")
257255
print(f"> INPT DIR = {args['inpt_dir']}")
258256
print(f"> CFG PATH = {args['cfg_path']}")
259257
print(f"> OUT DIR = {args['out_dir']}")
258+
259+
print("=" * 46 + " STATUS " + "=" * 46)
260+
print(f"> ELAPSED TIME = {elapsed_str}")
260261
print(f"> GLOBAL BEST SOLUTION = {global_data.best_sol}")
261262
print(f"> GLOBAL EARLY STOPPING COUNTER = {global_data.early_stop_counter.value}")
262263

@@ -314,6 +315,7 @@ def cli_logger(
314315
os.system("cls" if os.name == "nt" else "clear")
315316

316317
_print_global_status(args, global_data)
318+
print("=" * 46 + " LOGS " + "=" * 46)
317319
for i in sorted(island_logs.keys()):
318320
current_epoch = island_epochs.get(i, "N/A")
319321
print(f"=== ISLAND {i} | EPOCH {current_epoch} ===")

0 commit comments

Comments
 (0)