audit

package
v0.260224.1130 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 24, 2026 License: MPL-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Console    bool // Log to console in addition to file
	MaxEntries int  // Maximum entries to keep in memory (0 = unlimited)
}

Config holds logger configuration

type Entry

type Entry struct {
	Timestamp  time.Time              `json:"timestamp"`
	Level      Level                  `json:"level"`
	Action     string                 `json:"action"`
	UserID     string                 `json:"user_id,omitempty"`
	ClientIP   string                 `json:"client_ip,omitempty"`
	SessionID  string                 `json:"session_id,omitempty"`
	RequestID  string                 `json:"request_id,omitempty"`
	Success    bool                   `json:"success"`
	Message    string                 `json:"message,omitempty"`
	Details    map[string]interface{} `json:"details,omitempty"`
	DurationMs int64                  `json:"duration_ms,omitempty"`
}

Entry represents an audit log entry

type Level

type Level string

Level represents audit log level

const (
	LevelInfo  Level = "info"
	LevelWarn  Level = "warn"
	LevelError Level = "error"
)

func (Level) String

func (l Level) String() string

String returns the string representation of the level

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger handles audit logging

func NewLogger

func NewLogger(cfg Config) *Logger

NewLogger creates a new audit logger

func (*Logger) Clear

func (l *Logger) Clear()

Clear removes all entries

func (*Logger) Error

func (l *Logger) Error(action, userID, clientIP, message string, success bool, details map[string]interface{})

Error logs an error level entry

func (*Logger) ExportJSON

func (l *Logger) ExportJSON() ([]byte, error)

ExportJSON exports all entries as JSON

func (*Logger) ExportJSONToFile

func (l *Logger) ExportJSONToFile(path string) error

ExportJSONToFile exports entries to a file

func (*Logger) GetEntries

func (l *Logger) GetEntries() []Entry

GetEntries returns all audit entries

func (*Logger) GetEntriesBySession

func (l *Logger) GetEntriesBySession(sessionID string) []Entry

GetEntriesBySession returns entries for a specific session

func (*Logger) GetEntriesByUser

func (l *Logger) GetEntriesByUser(userID string) []Entry

GetEntriesByUser returns entries for a specific user

func (*Logger) GetLogs

func (l *Logger) GetLogs() []*Entry

GetLogs returns all audit entries as pointer slice (for API responses)

func (*Logger) Info

func (l *Logger) Info(action, userID, clientIP, message string, details map[string]interface{})

Info logs an info level entry

func (*Logger) Log

func (l *Logger) Log(entry Entry)

Log records an audit entry

func (*Logger) LogRequest

func (l *Logger) LogRequest(action, userID, clientIP, sessionID, requestID string, success bool, duration time.Duration, details map[string]interface{})

LogRequest logs a complete API request

func (*Logger) Size

func (l *Logger) Size() int

Size returns the number of entries

func (*Logger) Warn

func (l *Logger) Warn(action, userID, clientIP, message string, details map[string]interface{})

Warn logs a warning level entry

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL