From 7313421ae4e9ad114a834f4d05e2ad9b2b285e2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=AE=AE=E0=AE=A9=E0=AF=8B=E0=AE=9C=E0=AF=8D=E0=AE=95?= =?UTF-8?q?=E0=AF=81=E0=AE=AE=E0=AE=BE=E0=AE=B0=E0=AF=8D=20=E0=AE=AA?= =?UTF-8?q?=E0=AE=B4=E0=AE=A9=E0=AE=BF=E0=AE=9A=E0=AF=8D=E0=AE=9A=E0=AE=BE?= =?UTF-8?q?=E0=AE=AE=E0=AE=BF?= Date: Thu, 16 May 2024 16:05:18 +0530 Subject: [PATCH] Enabled LLM logs by default (#1819) Co-authored-by: Yufan Song <33971064+yufansong@users.noreply.github.com> --- .github/ISSUE_TEMPLATE/bug_template.yml | 2 +- opendevin/core/logger.py | 21 ++++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_template.yml b/.github/ISSUE_TEMPLATE/bug_template.yml index b8f25e47db..ba5382686b 100644 --- a/.github/ISSUE_TEMPLATE/bug_template.yml +++ b/.github/ISSUE_TEMPLATE/bug_template.yml @@ -66,4 +66,4 @@ body: id: additional-context attributes: label: Logs, Errors, Screenshots, and Additional Context - description: If you set DEBUG = 1 in config or env, LLM logs will be stored in the `logs/llm` folder. Please add any additional context about the problem here. + description: LLM logs will be stored in the `logs/llm/default` folder. Please add any additional context about the problem here. diff --git a/opendevin/core/logger.py b/opendevin/core/logger.py index b62cd12cb8..c5a02bb09e 100644 --- a/opendevin/core/logger.py +++ b/opendevin/core/logger.py @@ -150,9 +150,22 @@ class LlmFileHandler(logging.FileHandler): """ self.filename = filename self.message_counter = 1 - self.session = datetime.now().strftime('%y-%m-%d_%H-%M') + if config.debug: + self.session = datetime.now().strftime('%y-%m-%d_%H-%M') + else: + self.session = 'default' self.log_directory = os.path.join(os.getcwd(), 'logs', 'llm', self.session) os.makedirs(self.log_directory, exist_ok=True) + if not config.debug: + # Clear the log directory if not in debug mode + for file in os.listdir(self.log_directory): + file_path = os.path.join(self.log_directory, file) + try: + os.unlink(file_path) + except Exception as e: + opendevin_logger.error( + 'Failed to delete %s. Reason: %s', file_path, e + ) filename = f'{self.filename}_{self.message_counter:03}.log' self.baseFilename = os.path.join(self.log_directory, filename) super().__init__(self.baseFilename, mode, encoding, delay) @@ -195,12 +208,10 @@ def get_llm_response_file_handler(): llm_prompt_logger = logging.getLogger('prompt') llm_prompt_logger.propagate = False -if config.debug: - llm_prompt_logger.setLevel(logging.DEBUG) +llm_prompt_logger.setLevel(logging.DEBUG) llm_prompt_logger.addHandler(get_llm_prompt_file_handler()) llm_response_logger = logging.getLogger('response') llm_response_logger.propagate = False -if config.debug: - llm_response_logger.setLevel(logging.DEBUG) +llm_response_logger.setLevel(logging.DEBUG) llm_response_logger.addHandler(get_llm_response_file_handler())