File size: 703 Bytes
f54201d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19


# ./agent_logging.py
# The Logger - Ensures that all agent actions, observations, and errors are logged to a localized log file for traceability and debugging purposes.

import os
from datetime import datetime

def log_agent_action(action_type, message):
    """Logs all agent actions, observations, and errors to a localized log file."""
    output_dir = "outputs"
    if not os.path.exists(output_dir):
        os.makedirs(output_dir)
        
    log_path = os.path.join(output_dir, "agent.log")
    timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    
    with open(log_path, "a", encoding="utf-8") as log_file:
        log_file.write(f"[{timestamp}] [{action_type.upper()}] {message}\n")