mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-08 15:48:29 +00:00
* log_file feature: added a new parameter for crew that creates a txt file to log agent execution * unit tests and documentation unit test if file is created but not what is inside the file
21 lines
709 B
Python
21 lines
709 B
Python
import os
|
|
from datetime import datetime
|
|
|
|
|
|
class FileHandler:
|
|
"""take care of file operations, currently it only logs messages to a file"""
|
|
|
|
def __init__(self, file_path):
|
|
if isinstance(file_path, bool):
|
|
self._path = os.path.join(os.curdir, "logs.txt")
|
|
elif isinstance(file_path, str):
|
|
self._path = file_path
|
|
else:
|
|
raise ValueError("file_path must be either a boolean or a string.")
|
|
|
|
def log(self, **kwargs):
|
|
now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
message = f"{now}: ".join([f"{key}={value}" for key, value in kwargs.items()])
|
|
with open(self._path, "a") as file:
|
|
file.write(message + "\n")
|