Documentation
¶
Index ¶
- type AuditEntry
- type Change
- type Logger
- func (l *Logger) Close() error
- func (l *Logger) LoadEntries() ([]AuditEntry, error)
- func (l *Logger) LogConfig(provider, action string, changes []Change) error
- func (l *Logger) LogDefault(provider string) error
- func (l *Logger) LogFailure(event, provider, errMsg string, details map[string]interface{}) error
- func (l *Logger) LogMigration(details map[string]interface{}) error
- func (l *Logger) LogReset(provider string) error
- func (l *Logger) LogRotate(provider string) error
- func (l *Logger) LogSetup(provider string) error
- func (l *Logger) LogSuccess(event, provider string, details map[string]interface{}) error
- func (l *Logger) LogSwitch(provider string) error
- func (l *Logger) RotateLog(opts ...RotateOptions) (bool, error)
- type RotateOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuditEntry ¶
type AuditEntry struct {
Timestamp time.Time `json:"timestamp"`
Event string `json:"event"`
Provider string `json:"provider,omitempty"`
Action string `json:"action,omitempty"`
Status string `json:"status,omitempty"`
Error string `json:"error,omitempty"`
Details map[string]interface{} `json:"details,omitempty"`
Changes []Change `json:"changes,omitempty"`
// Context fields for traceability
Hostname string `json:"hostname,omitempty"`
Username string `json:"username,omitempty"`
SessionID string `json:"session_id,omitempty"`
}
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
func (*Logger) Close ¶ added in v1.5.0
Close closes the log file. Must be called when the logger is no longer needed.
func (*Logger) LoadEntries ¶
func (l *Logger) LoadEntries() ([]AuditEntry, error)
LoadEntries reads and parses all audit entries from the log file.
This method reads the entire audit log, parses each JSON line, and returns all entries as a slice. Empty lines are skipped. The log file is opened in read-only mode.
Parameters:
- none (method receiver only)
Returns:
- []AuditEntry: Slice of all audit entries in chronological order
- error: Returns error if unable to read or parse audit log
Error conditions:
- Returns error when audit log file cannot be read (e.g., permissions, file not found)
- Returns error if any JSON line cannot be parsed (e.g., corrupted log file)
Thread Safety: Thread-safe (uses RWMutex to allow concurrent reads) Security Notes: Returns all audit entries including potentially sensitive data
func (*Logger) LogConfig ¶
LogConfig logs a configuration change event to the audit log.
This method creates an audit entry recording when a provider's configuration is modified (added, updated, or changed). The entry includes provider name, action type (add/update), and list of changed fields with old and new values.
Parameters:
- provider: Name of the provider being configured
- action: Type of configuration action (e.g., "add", "update", "change")
- changes: List of fields that were changed with old/new values
Returns:
- error: Returns error if unable to write to audit log
Error conditions:
- Returns error when audit log file cannot be written (e.g., permissions, disk full)
Thread Safety: Thread-safe (uses mutex in writeEntry)
func (*Logger) LogDefault ¶
func (*Logger) LogFailure ¶ added in v1.5.0
LogFailure logs a failed operation with error details
func (*Logger) LogMigration ¶ added in v1.6.0
LogMigration logs a configuration file migration event
func (*Logger) LogSuccess ¶ added in v1.5.0
LogSuccess logs a successful operation with optional details
func (*Logger) LogSwitch ¶
LogSwitch logs a provider switch event to the audit log.
This method creates an audit entry recording when a user switches to a different provider. The entry includes the provider name and timestamp.
Parameters:
- provider: Name of the provider being switched to
Returns:
- error: Returns error if unable to write to audit log
Error conditions:
- Returns error when audit log file cannot be written (e.g., permissions, disk full)
Thread Safety: Thread-safe (uses mutex in writeEntry)
type RotateOptions ¶ added in v1.10.0
type RotateOptions struct {
// MaxSize is the maximum size in bytes before rotating (default: 10MB)
MaxSize int64
// MaxAge is the maximum age in days before rotating (default: 30 days)
MaxAge int
// MaxBackups is the number of old log files to keep (default: 5)
MaxBackups int
}
RotateOptions contains configuration options for log rotation.
func DefaultRotateOptions ¶ added in v1.10.0
func DefaultRotateOptions() RotateOptions
DefaultRotateOptions returns sensible defaults for log rotation.