← All Go packages
github.com/anulum/director-ai/gateway/internal/audit
package audit // import "github.com/anulum/director-ai/gateway/internal/audit"
Package audit serialises one AuditRecord per HTTP response to a JSONL file or
stdout. Matches the shape of “director_ai.core.safety.audit.AuditLogger“ on the
Python side so downstream consumers see one unified log regardless of which
front door handled the request.
TYPES
type Logger struct {
// Has unexported fields.
}
Logger writes AuditRecords to one io.Writer under a mutex.
func New(w io.Writer) *Logger
New returns a Logger writing to “w“. If “w“ is nil the logger writes to
os.Stdout.
func NewFile(path string) (*Logger, error)
NewFile opens “path“ in append mode and returns a Logger backed by it.
The file is created with 0o600 — audit logs may contain tenant fingerprints
and must not be world-readable.
func (l *Logger) Close() error
Close releases the underlying writer if it implements io.Closer.
func (l *Logger) Log(rec *Record) error
Log writes one record. Timestamp is filled automatically when empty.
type Record struct {
Timestamp string `json:"timestamp"`
RequestID string `json:"request_id"`
APIKeyFingerprint string `json:"api_key_fingerprint"`
Method string `json:"method"`
Path string `json:"path"`
Status int `json:"status"`
LatencyMS int64 `json:"latency_ms"`
BytesIn int64 `json:"bytes_in"`
BytesOut int64 `json:"bytes_out"`
Upstream string `json:"upstream,omitempty"`
PolicyViolations []string `json:"policy_violations,omitempty"`
}
Record is the wire shape. Field order kept stable so line-by-line diffs stay
readable.