audit

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: Apache-2.0 Imports: 9 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

Overview

Package audit writes an append-only JSON Lines log of a server's administrative and security-relevant events — kicks, replaced sessions, operator commands and destructive calls — with the actor and the subject of each, so support questions, anti-cheat review and accountability for admin power have a trail that survives restarts. One file per UTC day rolls at midnight; the files are text, greppable and shippable to a log store, and need no database.

Index

Constants

View Source
const DefaultQueue = 4096

DefaultQueue is a Writer's buffer size when Options.Queue is 0.

View Source
const SchemaVersion = 1

SchemaVersion is the record schema's version, written as each line's "v".

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	// Dir is the directory the log lives in, one <yyyy-mm-dd>.jsonl file per
	// UTC day, created when missing. Required.
	Dir string
	// Queue is how many records buffer while the writer appends earlier
	// ones, DefaultQueue when 0. Log drops and counts a record past it
	// rather than blocking the caller.
	Queue int
	// Retain is how many days of files to keep, counting back from the day
	// of the record being written; older files are deleted as the log opens
	// a new day's file. 0 keeps every file.
	Retain int
}

Options are a Writer's settings.

type Record

type Record struct {
	// V is the schema version; Log fills in SchemaVersion when 0.
	V int `json:"v"`
	// Time is when the event happened; Log fills in the current time when
	// zero. The record lands in the file of its own UTC day, so a replayed
	// batch lands in the files of the days it happened.
	Time time.Time `json:"time"`
	// Actor is the account ID, an admin token subject, or "system" when empty.
	Actor string `json:"actor"`
	// Action is what happened, such as "peer.kick", "session.replaced" or
	// "admin.run".
	Action string `json:"action"`
	// Subject is what the action acted on: a peer, an account, a board/slot.
	Subject string `json:"subject"`
	// Data holds the action's details; omitted from the line when empty.
	Data map[string]any `json:"data,omitempty"`
}

Record is one audited event: who did what to whom, with the action's details in Data.

type Writer

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

Writer appends records to the day's file on one background goroutine, fsyncing in batches. It is safe for concurrent use.

func Open

func Open(o Options) (*Writer, error)

Open returns a Writer logging to o.Dir, creating the directory when missing.

func (*Writer) Close

func (w *Writer) Close() error

Close flushes the queued records, fsyncs and closes the file, and returns the first append failure, if any. It is safe to call twice.

func (*Writer) Dropped

func (w *Writer) Dropped() uint64

Dropped reports how many records never reached the file: they arrived while the queue was full, after Close, or their append failed.

func (*Writer) Log

func (w *Writer) Log(r Record)

Log queues a record, filling in its schema version, time and actor when unset. It never blocks: a record that does not fit in the queue is dropped and counted by Dropped, as is one logged after Close.

Jump to

Keyboard shortcuts

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