This commit is contained in:
h z
2026-02-15 08:49:27 +00:00
commit 72843442ac
21 changed files with 1450 additions and 0 deletions

46
audit/logger.go Normal file
View File

@@ -0,0 +1,46 @@
package audit
import (
"encoding/json"
"log"
"os"
"time"
)
// Entry represents a single audit log record.
type Entry struct {
Timestamp string `json:"timestamp"`
RemoteIP string `json:"remote_ip"`
Action string `json:"action"`
Path string `json:"path"`
Summary string `json:"summary"`
}
// Logger writes structured audit entries as JSON to stdout.
type Logger struct {
out *log.Logger
}
// NewLogger creates a new audit logger writing to stdout.
func NewLogger() *Logger {
return &Logger{
out: log.New(os.Stdout, "", 0),
}
}
// Log writes a structured audit entry.
func (l *Logger) Log(remoteIP, action, path, summary string) {
entry := Entry{
Timestamp: time.Now().UTC().Format(time.RFC3339),
RemoteIP: remoteIP,
Action: action,
Path: path,
Summary: summary,
}
data, err := json.Marshal(entry)
if err != nil {
l.out.Printf(`{"error":"failed to marshal audit entry: %v"}`, err)
return
}
l.out.Print(string(data))
}