histlog

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 12 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 histlog is the history log: one JSON line appended for each change sitrep makes to its state, and none for a read. It is a record beside the files, which stay the source of truth, and nothing replays it. See docs/HISTORY-LOG.md.

Index

Constants

View Source
const (
	QueueAdd     = "queue.add"
	QueueRm      = "queue.rm"
	QueueEdit    = "queue.edit"
	QueueMove    = "queue.move"
	QueueReorder = "queue.reorder"
	Pin          = "pin"
	Unpin        = "unpin"
	Snooze       = "snooze"
	Unsnooze     = "unsnooze"
	Alias        = "alias"
	Prune        = "prune"
	SessionStart = "session.start"
	SessionEnd   = "session.end"
)

The operations a log records.

Variables

This section is empty.

Functions

func Host

func Host(name string) string

Host makes a name for a machine that is safe to store and show: letters, digits, underscore and hyphen, at most 64 of them.

func KnownOp

func KnownOp(op string) bool

KnownOp says whether op is one of the operations a log records.

Types

type Entry

type Entry struct {
	Op   string
	ID   state.ID      // the session, or the inbox
	Text textsafe.Text // the item, the Objective or the name
	Old  textsafe.Text // queue.edit: the text before; alias: the name before
	From int           // queue.reorder: the position the item left
	To   int           // queue.reorder: the position it took
	Dest state.ID      // queue.move: the queue it went to, with ID as the queue it left
}

Entry is one change. It describes the outcome, not the command: items are named by their text, and a position is a fact about the moment.

type Item

type Item struct {
	E    string
	Time time.Time
	Host string
	ID   state.ID
	Op   string
	Text textsafe.Text
	Old  textsafe.Text
	From int
	To   int
	Dest state.ID
}

Item is an entry as a reader sees it. Every text in it has been made safe again, because the file is untrusted.

func Read

func Read(dir string, q Query) []Item

Read returns the entries that match, oldest first. A line that does not parse is skipped, which covers a torn last line, and a line whose entry id was already seen is a repeat and is dropped. It reads the previous file and then the current one.

type Log

type Log struct {
	Dir   string // the state folder
	Host  string // the name of this host, as Host makes it
	On    bool
	MaxMB int // the size limit for both files together
	Days  int // the age limit
	Now   func() time.Time
}

Log writes entries to one host's files. The zero Log is off and writes nothing.

func (Log) Clear

func (l Log) Clear() error

Clear removes the log files, each by its own path, and then the folder if that is now empty.

func (Log) Record

func (l Log) Record(e Entry)

Record appends an entry. It is called after the change succeeded, and it never fails: on any error the entry is dropped (invariant 4).

type Query

type Query struct {
	Host  string   // only this host; empty means every host in the folder
	ID    state.ID // only this queue or session (as a source or a destination); empty means all
	Op    string   // only this operation
	Since time.Time
	Days  int // entries older than this many days are ignored, whatever Since says
	Now   time.Time
	Limit int // the most recent this many, or all when below 1
}

Query chooses what Read returns.

Jump to

Keyboard shortcuts

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