Documentation
¶
Index ¶
- Constants
- Variables
- func NewJSONHandler(out io.Writer, level *slog.LevelVar, component string, redactor *Redactor) slog.Handler
- func ParseLevel(level string) (slog.Level, error)
- type Config
- type ExportPaths
- type ExportRange
- type ExportRequest
- type ExportResult
- type FailureClass
- type FailureReporter
- type Group
- type LineCaptureWriter
- type RangeKind
- type Redactor
- type RotatingWriter
- type RotatorOptions
- type Runtime
- type RuntimeOptions
Constants ¶
const ( // MaxCaptureLineBytes is the per-line capture cap for mihomo stdout/stderr. MaxCaptureLineBytes = 16 << 10 // MaxExportRecordBytes is the per-record export parse cap. MaxExportRecordBytes = 1 << 20 )
Variables ¶
var ( // ErrInvalidExportRequest identifies an unsupported range or destination. ErrInvalidExportRequest = errors.New("invalid export request") // ErrExportTargetExists identifies a destination that must not be overwritten. ErrExportTargetExists = errors.New("export target already exists") // ErrExportTargetChanged identifies failed destination identity or containment checks. ErrExportTargetChanged = errors.New("export target changed") // ErrNoLogLines reports that no valid records matched the selected range. ErrNoLogLines = errors.New("no log lines in selected range") )
Functions ¶
Types ¶
type Config ¶
Config is the runtime logging level and rotation limits.
func BootstrapConfig ¶
func BootstrapConfig() Config
BootstrapConfig is the conservative TUI bootstrap: debug, 100 MiB, 10 files.
func ConfigFromFields ¶
ConfigFromFields validates persisted/API fields and converts MiB to bytes.
type ExportPaths ¶
type ExportPaths struct {
LogDir string
ExportDir string
DaemonLog string
TUILog string
MihomoLog string
}
ExportPaths contains the private logging and default export paths.
type ExportRange ¶
ExportRange describes the requested closed time window.
type ExportRequest ¶
type ExportRequest struct {
Now time.Time
Range ExportRange
OutputPath string
AutoNumber bool
Paths ExportPaths
PrivateFS *platform.PrivateFS
OpenLock func(*platform.PrivateFS, string) (platform.AdvisoryLock, error)
EnterRecordMutex func(basePath string) func()
Redactor *Redactor
OnWarning func(error)
}
ExportRequest contains one immutable log export request.
type ExportResult ¶
type ExportResult struct {
Path string
}
ExportResult identifies the published archive.
func Export ¶
func Export(ctx context.Context, request ExportRequest) (ExportResult, error)
Export creates a redacted archive and atomically publishes it.
type FailureClass ¶
type FailureClass string
FailureClass is a stable, rate-limited stderr category.
const ( FailureDropped FailureClass = "dropped" FailureWrite FailureClass = "write" FailureRotate FailureClass = "rotate" FailureCleanup FailureClass = "cleanup" )
type FailureReporter ¶
type FailureReporter interface {
Report(class FailureClass, err error)
}
FailureReporter records classified logging failures.
func NewFailureReporter ¶
NewFailureReporter writes rate-limited, redacted failure lines without full paths.
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
Group applies one config to multiple runtimes (daemon and mihomo).
func (*Group) Apply ¶
Apply swaps config on every target, then converges archives one by one. It must not call Runtime.Apply per target.
type LineCaptureWriter ¶
type LineCaptureWriter interface {
io.WriteCloser
Flush() error
}
LineCaptureWriter splits arbitrary stdout/stderr chunks into JSONL records.
func NewLineCaptureWriter ¶
NewLineCaptureWriter returns a writer that logs each logical line at level with stream set. Write returns len(p), nil unless the writer is closed.
type RangeKind ¶
type RangeKind string
RangeKind identifies a supported log export time window.
const ( // RangeLast24Hours selects the 24 hours ending at export time. RangeLast24Hours RangeKind = "last_24h" // RangeLast60Minutes selects the 60 minutes ending at export time. RangeLast60Minutes RangeKind = "last_60m" // RangeBetween selects an explicit closed time interval. RangeBetween RangeKind = "between" // RangeAll selects every valid timestamped record. RangeAll RangeKind = "all" )
type Redactor ¶
type Redactor struct {
// contains filtered or unexported fields
}
Redactor applies immutable exact-secret and generic redaction rules to log text and attrs.
func NewRedactor ¶
NewRedactor builds a redactor and registers optional exact secrets.
func (*Redactor) ReplaceAttr ¶
ReplaceAttr recursively redacts slog attributes. Sensitive keys and sensitive ancestor groups replace values with ***; strings, errors, and LogValuer results run through String.
func (*Redactor) ReplaceExact ¶
ReplaceExact replaces the exact-secret snapshot. Empty and too-short values are dropped; remaining values are copied and sorted longest-first. Generic regexes are package-level.
type RotatingWriter ¶
type RotatingWriter struct {
// contains filtered or unexported fields
}
RotatingWriter appends full JSONL records with overflow-safe rotation.
func OpenRotatingWriter ¶
func OpenRotatingWriter(ctx context.Context, opts RotatorOptions) (*RotatingWriter, error)
OpenRotatingWriter creates the lock, converges archives, and creates the base file. The initial lock wait uses the earlier of the caller deadline and the hard write-wait bound. On failure, acquired resources are closed.
func (*RotatingWriter) Apply ¶
func (w *RotatingWriter) Apply(ctx context.Context, cfg Config)
Apply atomically stores cfg, then waits min(ctx deadline, WriteWait) for the exclusive lock and converges archives. Lock timeout or ctx cancel skip maintenance; the swapped config is kept. After the lock is held, ReadDir and Remove are not canceled.
func (*RotatingWriter) Close ¶
func (w *RotatingWriter) Close() error
Close closes the current write handle and lock. It does not close PrivateFS.
func (*RotatingWriter) Dropped ¶
func (w *RotatingWriter) Dropped() uint64
Dropped returns the number of records dropped because the write lock wait failed.
func (*RotatingWriter) Write ¶
func (w *RotatingWriter) Write(p []byte) (n int, err error)
Write appends one complete JSONL record. It takes the process mutex, then an exclusive advisory lock (WriteWait, default 250ms). After the lock it opens and Stats the base file. A lock wait failure drops the whole record.
type RotatorOptions ¶
type RotatorOptions struct {
BasePath string
Config Config
PrivateFS *platform.PrivateFS
OpenLock func(*platform.PrivateFS, string) (platform.AdvisoryLock, error)
WriteWait time.Duration
Reporter FailureReporter
}
RotatorOptions opens a process-safe rotating JSONL writer.
type Runtime ¶
type Runtime struct {
// contains filtered or unexported fields
}
Runtime owns a slog logger, LevelVar, and rotating writer for one log file.
func Open ¶
func Open(ctx context.Context, opts RuntimeOptions) (*Runtime, error)
Open creates the base log file and returns a runtime. ctx cancel aborts the initial lock wait. The shared PrivateFS is not owned by the runtime.
func (*Runtime) Apply ¶
Apply swaps level and rotator limits, then converges archives. A canceled context still completes the in-memory swap.
func (*Runtime) Close ¶
Close closes the rotator, lock, and current write handle. It does not close the shared PrivateFS.
func (*Runtime) EnterRecordMutex ¶
func (r *Runtime) EnterRecordMutex() func()
EnterRecordMutex locks the process-local record mutex and returns unlock.
type RuntimeOptions ¶
type RuntimeOptions struct {
BasePath string
Component string
Config Config
PrivateFS *platform.PrivateFS
OpenLock func(*platform.PrivateFS, string) (platform.AdvisoryLock, error)
Redactor *Redactor
Reporter FailureReporter
}
RuntimeOptions opens a component-scoped JSONL logging runtime.