From 5b428f509bb69b76c426aab3c19ba4c52fdb16ed Mon Sep 17 00:00:00 2001 From: Steve Date: Sun, 16 Apr 2023 14:33:20 +0000 Subject: [PATCH] fix file logging issue --- autogpt/commands/file_operations.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/autogpt/commands/file_operations.py b/autogpt/commands/file_operations.py index d02b125a..5350d2f4 100644 --- a/autogpt/commands/file_operations.py +++ b/autogpt/commands/file_operations.py @@ -45,7 +45,7 @@ def log_operation(operation: str, filename: str) -> None: with open(LOG_FILE_PATH, "w", encoding="utf-8") as f: f.write("File Operation Logger ") - append_to_file(LOG_FILE, log_entry) + append_to_file(LOG_FILE, log_entry, shouldLog = False) def safe_join(base: str, *paths) -> str: @@ -171,7 +171,7 @@ def write_to_file(filename: str, text: str) -> str: return f"Error: {str(e)}" -def append_to_file(filename: str, text: str) -> str: +def append_to_file(filename: str, text: str, shouldLog: bool = True) -> str: """Append text to a file Args: @@ -185,7 +185,10 @@ def append_to_file(filename: str, text: str) -> str: filepath = safe_join(WORKING_DIRECTORY, filename) with open(filepath, "a") as f: f.write(text) - log_operation("append", filename) + + if shouldLog: + log_operation("append", filename) + return "Text appended successfully." except Exception as e: return f"Error: {str(e)}"