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

cmdlog

package
v1.4.8 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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) 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.

Jump to

Keyboard shortcuts

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