feat: Log LLM responses to console

- Add a StreamHandler to the logger to output all logs to the console.
- Log the LLM response to the console for real-time monitoring.
- Update PROGRESS.md to reflect the completion of the task.
- Fix a syntax error in monitor_agent.py.
This commit is contained in:
2025-08-21 12:18:08 -05:00
parent f65b2d468d
commit d03018de9b
2 changed files with 13 additions and 6 deletions

View File

@@ -26,10 +26,15 @@ logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
# Create a handler that rotates logs daily, keeping 1 backup
handler = TimedRotatingFileHandler(LOG_FILE, when="midnight", interval=1, backupCount=1)
handler.setFormatter(logging.Formatter('%(asctime)s - %(levelname)s - %(message)s'))
file_handler = TimedRotatingFileHandler(LOG_FILE, when="midnight", interval=1, backupCount=1)
file_handler.setFormatter(logging.Formatter('%(asctime)s - %(levelname)s - %(message)s'))
logger.addHandler(handler)
# Create a handler for console output
console_handler = logging.StreamHandler()
console_handler.setFormatter(logging.Formatter('%(asctime)s - %(levelname)s - %(message)s'))
logger.addHandler(file_handler)
logger.addHandler(console_handler)
LOG_POSITION_FILE = 'log_position.txt'
@@ -257,7 +262,9 @@ def analyze_data_with_llm(data, baselines):
end_index = sanitized_response.rfind('}')
if start_index != -1 and end_index != -1:
json_string = sanitized_response[start_index:end_index+1]
return json.loads(json_string)
llm_response = json.loads(json_string)
logger.info(f"LLM Response: {llm_response}")
return llm_response
else:
# Handle cases where the response is not valid JSON
logger.warning(f"LLM returned a non-JSON response: {sanitized_response}")
@@ -379,4 +386,4 @@ def main():
time.sleep(300) # Run every 5 minutes
if __name__ == "__main__":
main()
main()