Enabled LLM logs by default (#1819)

Co-authored-by: Yufan Song <33971064+yufansong@users.noreply.github.com>
This commit is contained in:
மனோஜ்குமார் பழனிச்சாமி 2024-05-16 16:05:18 +05:30 committed by GitHub
parent 6cce9c3c28
commit 7313421ae4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 6 deletions

View File

@ -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.

View File

@ -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())