Spaces:
Sleeping
Sleeping
File size: 1,381 Bytes
96fc5b5 beae359 96fc5b5 beae359 96fc5b5 beae359 96fc5b5 beae359 96fc5b5 beae359 96fc5b5 beae359 96fc5b5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# codex_logger.py
# Author: Liam Grinstead
# Logs activation, mutation, and collapse with author credit and hash
# All logs are saved as JSON files with timestamp and SHA-512 seal
import json
import os
import hashlib
from datetime import datetime
LOG_DIR = "logs"
os.makedirs(LOG_DIR, exist_ok=True)
def log_artifact(agent, score, hash_val):
"""
Log an artifact with timestamp, agent details, fitness score, and SHA-512 seal.
Saves to logs directory as JSON.
"""
timestamp = datetime.utcnow().isoformat()
log = {
"timestamp": timestamp,
"agent_id": agent.get("id", "Unknown"),
"status": agent.get("status"),
"fitness_score": score,
"hash": hash_val,
"author": "Liam Grinstead"
}
# Seal the log entry itself
entry_str = json.dumps(log, sort_keys=True)
log["sha512"] = hashlib.sha512(entry_str.encode()).hexdigest()
# Save to file
filename = f"{LOG_DIR}/artifact_{timestamp}.json"
with open(filename, "w") as f:
json.dump(log, f, indent=2)
print("Artifact Logged:", log)
return log
def list_logs():
"""
List all saved logs.
"""
return sorted(os.listdir(LOG_DIR))
def load_log(filename):
"""
Load a specific log file.
"""
filepath = os.path.join(LOG_DIR, filename)
with open(filepath, "r") as f:
return json.load(f)
|