audit

package
v0.260709.1 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2026 License: MPL-2.0 Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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