update
This commit is contained in:
@@ -25,6 +25,7 @@ class AuditLogger:
|
||||
|
||||
# Ensure log directory exists
|
||||
self.log_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
self._log_file = self._get_log_file()
|
||||
|
||||
# Configure structlog for audit logging
|
||||
structlog.configure(
|
||||
@@ -35,7 +36,7 @@ class AuditLogger:
|
||||
],
|
||||
wrapper_class=structlog.BoundLogger,
|
||||
context_class=dict,
|
||||
logger_factory=structlog.PrintLoggerFactory(file=self._get_log_file()),
|
||||
logger_factory=structlog.PrintLoggerFactory(file=self._log_file),
|
||||
cache_logger_on_first_use=True,
|
||||
)
|
||||
|
||||
@@ -45,6 +46,13 @@ class AuditLogger:
|
||||
"""Get file handle for audit log."""
|
||||
return open(self.log_path, "a", encoding="utf-8")
|
||||
|
||||
def close(self) -> None:
|
||||
"""Close open audit log resources."""
|
||||
try:
|
||||
self._log_file.close()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def log_tool_invocation(
|
||||
self,
|
||||
tool_name: str,
|
||||
@@ -166,4 +174,6 @@ def get_audit_logger() -> AuditLogger:
|
||||
def reset_audit_logger() -> None:
|
||||
"""Reset global audit logger instance (primarily for testing)."""
|
||||
global _audit_logger
|
||||
if _audit_logger is not None:
|
||||
_audit_logger.close()
|
||||
_audit_logger = None
|
||||
|
||||
Reference in New Issue
Block a user