Spaces:
Sleeping
Sleeping
File size: 942 Bytes
86feafb | 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 | """Audit logging for RAG system"""
import json
import hashlib
from typing import Dict
class AuditLogger:
"""Comprehensive audit logging for queries and responses"""
def __init__(self, log_file: str = "audit_logs.jsonl"):
"""Initialize audit logger with log file path"""
self.log_file = log_file
def log(self, entry: Dict):
"""
Write audit entry to log file
Args:
entry: Dictionary containing audit information
"""
with open(self.log_file, 'a', encoding='utf-8') as f:
f.write(json.dumps(entry) + '\n')
@staticmethod
def hash_text(text: str) -> str:
"""
Hash text for privacy-preserving logging
Args:
text: Text to hash
Returns:
First 16 characters of SHA256 hash
"""
return hashlib.sha256(text.encode()).hexdigest()[:16]
|