diff --git a/src/art/langgraph/logging.py b/src/art/langgraph/logging.py index 4b50a9530..5df4d54b5 100644 --- a/src/art/langgraph/logging.py +++ b/src/art/langgraph/logging.py @@ -1,30 +1,29 @@ +import json import os -import pickle class FileLogger: def __init__(self, filepath): self.text_path = filepath - self.pickle_path = filepath + ".pkl" + self.jsonl_path = filepath + ".jsonl" def log(self, name, entry): # Log as readable text with open(self.text_path, "a") as f: f.write(f"{name}: {entry}\n") - # Append to pickle log - with open(self.pickle_path, "ab") as pf: - pickle.dump((name, entry), pf) + # Append to jsonl log + with open(self.jsonl_path, "a") as jf: + jf.write(json.dumps([name, entry]) + "\n") def load_logs(self): - """Load all logs from the pickle file.""" - if not os.path.exists(self.pickle_path): + """Load all logs from the jsonl file.""" + if not os.path.exists(self.jsonl_path): return [] logs = [] - with open(self.pickle_path, "rb") as pf: - try: - while True: - logs.append(pickle.load(pf)) - except EOFError: - pass + with open(self.jsonl_path, "r") as jf: + for line in jf: + line = line.strip() + if line: + logs.append(tuple(json.loads(line))) return logs