Documentation
¶
Overview ¶
Package audit provides file-based audit persistence with JSON Lines format, daily rotation, size caps, retention cleanup, and an in-memory cache.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuditFileConfig ¶
type AuditFileConfig struct {
// Dir is the directory where audit files are stored.
Dir string
// RetentionDays is the number of days to keep audit files (default 7).
RetentionDays int
// MaxFileSizeMB is the maximum file size in megabytes before rotation (default 100).
MaxFileSizeMB int
// CacheSize is the number of recent entries to keep in memory (default 1000).
CacheSize int
}
AuditFileConfig holds configuration for the file-based audit store.
type FileAuditStore ¶
type FileAuditStore struct {
// contains filtered or unexported fields
}
FileAuditStore implements audit.AuditStore with file rotation, retention, and cache.
func NewFileAuditStore ¶
func NewFileAuditStore(cfg AuditFileConfig, logger *slog.Logger) (*FileAuditStore, error)
NewFileAuditStore creates a new file-based audit store. It creates the directory if it does not exist, opens today's log file, runs retention cleanup, populates the cache from the most recent file, and starts the hourly cleanup goroutine.
func (*FileAuditStore) Append ¶
func (s *FileAuditStore) Append(ctx context.Context, records ...audit.AuditRecord) error
Append stores audit records as JSON Lines to the current audit file. It handles date and size rotation as needed.
func (*FileAuditStore) Close ¶
func (s *FileAuditStore) Close() error
Close releases resources, stops the cleanup goroutine, and closes the current file.
func (*FileAuditStore) Flush ¶
func (s *FileAuditStore) Flush(_ context.Context) error
Flush forces pending records to disk by syncing the current file.
func (*FileAuditStore) GetRecent ¶
func (s *FileAuditStore) GetRecent(n int) []audit.AuditRecord
GetRecent returns the last n audit records from the cache, newest first.