Help us shape the future of Go! Take the 2026 Go Developer Survey

cmdlog

package
v1.4.15 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MaskValues added in v1.4.14

func MaskValues(vals ...string)

MaskValues registers secret values every later Begin and finish scrubs from the log. Safe for concurrent use; empty values are skipped.

Types

type Entry

type Entry struct {
	Timestamp time.Time `json:"ts"`
	Command   string    `json:"cmd"`  // full argv joined, secrets redacted
	User      string    `json:"user"` // os.Getenv("USER")
	Duration  float64   `json:"dur_s"`
	ExitCode  int       `json:"exit"`
	Error     string    `json:"error,omitempty"`
}

Entry represents a single command execution log record.

type Logger

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

Logger appends JSON log lines to {logDir}/nself.log with rotation support.

func New

func New(logDir string) *Logger

New creates a Logger that writes to {logDir}/nself.log. The directory is created if it does not exist.

func (*Logger) Begin

func (l *Logger) Begin(argv []string, secrets ...string) func(exitCode int, err error)

Begin records the command start. The returned function must be deferred by the caller; it computes duration and appends the log entry. If NSELF_CMD_LOG_ENABLED is "false" or "0", a no-op function is returned.

secrets are values the caller knows are secret (a positional or flag value); they join the MaskValues set and are scrubbed from the argv and the error.

Jump to

Keyboard shortcuts

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