Documentation
¶
Index ¶
- Constants
- Variables
- func NewDiagnosticReporter(logger *slog.Logger, _ *Redactor) diagnostics.Reporter
- func NewJSONHandler(out io.Writer, level *slog.LevelVar, component string, _ *Redactor) slog.Handler
- func ParseLevel(level string) (slog.Level, error)
- func WithOperation(ctx context.Context, operation OperationMetadata) context.Context
- type Config
- type ExportPaths
- type ExportRange
- type ExportRequest
- type ExportResult
- type FailureClass
- type FailureReporter
- type Group
- type LineCaptureWriter
- type MachineSnapshotOptions
- type MachineSnapshotSource
- type NamedSource
- type OperationMetadata
- type RangeKind
- type Redactor
- type RotatingWriter
- type RotatorOptions
- type Runtime
- type RuntimeOptions
- type SnapshotSet
- type SnapshotSource
- type SnapshotWindow
- type SourceID
- type SourceReader
- type SourceStats
Constants ¶
const ( // ExportScopeMachineAndCurrentUser includes machine sources and the current user's TUI logs. ExportScopeMachineAndCurrentUser = "machine_and_current_user" // ExportScopeCurrentUserOnly is the explicit TUI-only export; it never auto-degrades. ExportScopeCurrentUserOnly = "current_user_only" // ExportSourceCollected means the named source was requested and finished. ExportSourceCollected = "collected" // ExportSourceNotRequested means the named source was omitted by the caller. ExportSourceNotRequested = "not_requested" ExportSourceUnavailable = "unavailable" )
const ( // LevelSilent disables ordinary file records, independently of severity. LevelSilent slog.Level = 100 // MaxCaptureLineBytes is the per-line capture cap for mihomo stdout/stderr. MaxCaptureLineBytes = 256 << 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 ¶
func NewDiagnosticReporter ¶ added in v0.9.3
func NewDiagnosticReporter(logger *slog.Logger, _ *Redactor) diagnostics.Reporter
NewDiagnosticReporter writes original internal causes to a file logger. The redactor argument is retained for existing owners that also use it for public fallback output; it does not alter file diagnostics.
func NewJSONHandler ¶
func NewJSONHandler(out io.Writer, level *slog.LevelVar, component string, _ *Redactor) slog.Handler
NewJSONHandler returns a slog JSON handler that stamps component, formats time as RFC3339Nano with a numeric offset, and preserves original log content. Redaction for public fallback output is owned separately by the caller.
func ParseLevel ¶
ParseLevel converts a persisted logging level to its slog level.
func WithOperation ¶ added in v0.9.3
func WithOperation(ctx context.Context, operation OperationMetadata) context.Context
WithOperation attaches a copy of operation to a non-nil context.
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 Assemble ¶ added in v0.9.3
func Assemble(ctx context.Context, request ExportRequest, scope string, sources []NamedSource, finish func(context.Context) error) (ExportResult, error)
Assemble consumes NamedSource readers, then finish, then publishes a ZIP.
func Export ¶
func Export(ctx context.Context, request ExportRequest) (ExportResult, error)
Export preserves diagnostic content in an 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.
func NewMihomoCaptureWriter ¶ added in v0.9.5
func NewMihomoCaptureWriter(logger *slog.Logger, fallback slog.Level, stream string) LineCaptureWriter
NewMihomoCaptureWriter recognizes core severity while preserving raw messages.
type MachineSnapshotOptions ¶ added in v0.9.3
type MachineSnapshotOptions struct {
PrivateFS *platform.PrivateFS
Paths ExportPaths
EnterRecordMutex func(context.Context, string) (func(), error)
Redactor *Redactor
}
MachineSnapshotOptions contains daemon-owned storage and writer synchronization.
type MachineSnapshotSource ¶ added in v0.9.3
type MachineSnapshotSource interface {
Open(context.Context, SnapshotWindow) (SnapshotSet, error)
}
MachineSnapshotSource opens daemon and mihomo prefixes with no client path input.
func NewMachineSnapshotSource ¶ added in v0.9.3
func NewMachineSnapshotSource(options MachineSnapshotOptions) MachineSnapshotSource
NewMachineSnapshotSource borrows the daemon's logging filesystem.
type NamedSource ¶ added in v0.9.3
type NamedSource struct {
ID SourceID
Source SnapshotSource
}
NamedSource binds an export input to its fixed archive entry.
func NamedSourcesFromSet ¶ added in v0.9.3
func NamedSourcesFromSet(set SnapshotSet) []NamedSource
NamedSourcesFromSet borrows daemon then mihomo readers from a SnapshotSet.
type OperationMetadata ¶ added in v0.9.3
OperationMetadata identifies a logical operation in diagnostic logs.
func OperationFromContext ¶ added in v0.9.3
func OperationFromContext(ctx context.Context) (OperationMetadata, bool)
OperationFromContext returns operation metadata explicitly bound to ctx.
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.
func (*Redactor) RetainCredential ¶ added in v0.9.3
RetainCredential keeps a successfully loaded control credential redacted for this redactor's lifetime, including after configured secrets are replaced.
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.
func (*Runtime) EnterRecordMutexContext ¶ added in v0.9.3
EnterRecordMutexContext acquires the same gate as logging and rotation, with cancellation while waiting. The returned release must be called exactly once.
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.
type SnapshotSet ¶ added in v0.9.3
type SnapshotSet interface {
Source(SourceID) (SourceReader, error)
Finish(context.Context) error
Close() error
}
SnapshotSet owns both source readers, consumed in daemon then mihomo order. Finish is required before an assembler publishes any output.
type SnapshotSource ¶ added in v0.9.3
type SnapshotSource interface {
Open(context.Context, SnapshotWindow) (SourceReader, error)
}
SnapshotSource opens a bounded prefix of one fixed log sequence.
func NewFileSnapshotSource ¶ added in v0.9.3
func NewFileSnapshotSource(id SourceID, options MachineSnapshotOptions) SnapshotSource
NewFileSnapshotSource reads one local log sequence; TUI is capped at 10 files / 1GiB.
type SnapshotWindow ¶ added in v0.9.3
SnapshotWindow is an immutable closed UTC interval; nil From means no lower bound.
type SourceID ¶ added in v0.9.3
type SourceID string
SourceID identifies a fixed diagnostic stream, never a filesystem path.
type SourceReader ¶ added in v0.9.3
type SourceReader interface {
Next(context.Context) ([]byte, bool, error)
Finish(context.Context) (SourceStats, error)
Close() error
}
SourceReader emits one JSON object at a time; Finish requires successful EOF. Next and Finish are called serially by the consumer.