histlog

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: MIT Imports: 13 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"
	Restore      = "restore" // one entry for a whole restore: counts, and no item text
)

The operations a log records.

Variables

This section is empty.

Functions

func Canonical added in v1.0.7

func Canonical(data []byte) (out []byte, kept, dropped int)

Canonical reads the bytes of a log file that came from somewhere else, and writes them again the way this package writes a log: a line that is not valid JSON, that is too long, that has an operation or a host or an id this package does not know, or that repeats the id of an entry already kept, is dropped, and the text fields are cleaned and cut. What remains is made only from fields that this package has parsed, so nothing else of the original gets through. It says how many lines it kept and how many it dropped; an empty line is neither.

func CanonicalAll added in v1.0.7

func CanonicalAll(files ...[]byte) (outs [][]byte, kept, dropped int)

CanonicalAll is Canonical for several files that make one log (the previous and the current), in the order given: an entry id that one file has kept is dropped from the next, as the reader reads the two files as one.

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) Check added in v1.0.7

func (l Log) Check() error

Check says whether the log folder can be used: it is made when it is not there, and a link or a file where it belongs is an error.

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

func (Log) Replace added in v1.0.7

func (l Log) Replace(current, previous []byte) error

Replace makes the two log files of this folder what the arguments are, under the log's lock: each is written to a temporary file in the log folder first, and only then are the two renamed, one after the other, so that a failure while writing leaves the log as it was. A nil argument removes that file. The caller has made the bytes with Canonical. An entry that another process appends while this runs may be lost, since appends do not take the lock.

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