logging

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: May 24, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnsureLogDir

func EnsureLogDir(logDir string) error

EnsureLogDir ensures the git-undo log directory exists.

Types

type Entry

type Entry struct {
	// Timestamp is parsed timestamp of the entry.
	Timestamp time.Time
	// Ref is reference (branch/tag/commit) where the command was executed.
	Ref string
	// Command is just the command part.
	Command string

	// Undoed is true if the entry is undoed.
	Undoed bool
}

Entry represents a logged git command with its full identifier.

func (*Entry) GetIdentifier

func (e *Entry) GetIdentifier() string

GetIdentifier returns full command without sign of undoed state (# prefix).

func (*Entry) MarshalText

func (e *Entry) MarshalText() ([]byte, error)

func (*Entry) String

func (e *Entry) String() string

String returns a human-readable representation of the entry. This representation goes into the log file as well.

func (*Entry) UnmarshalText

func (e *Entry) UnmarshalText(data []byte) error

type EntryType

type EntryType int

EntryType specifies whether to look for regular or undoed entries.

const (
	NotSpecifiedEntryType EntryType = iota

	// RegularEntry represents a normal, non-undoed entry.
	RegularEntry
	// UndoedEntry represents an entry that has been marked as undoed.
	UndoedEntry
)

func (EntryType) String

func (et EntryType) String() string

String returns the string representation of the EntryType.

type GitHelper

type GitHelper interface {
	GetCurrentGitRef() (string, error)
}

type Logger

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

Logger manages git command logging operations.

func NewLogger

func NewLogger(repoGitDir string, git GitHelper) *Logger

NewLogger creates a new Logger instance.

func (*Logger) Dump

func (l *Logger) Dump(w io.Writer) error

Dump reads the log file content and writes it directly to the provided writer.

func (*Logger) GetLastEntry

func (l *Logger) GetLastEntry(refArg ...string) (*Entry, error)

GetLastEntry returns last entry for the given ref (or current ref if not specified) regarding of the entry type (undoed or regular).

func (*Logger) GetLastRegularEntry added in v0.0.2

func (l *Logger) GetLastRegularEntry(refArg ...string) (*Entry, error)

GetLastRegularEntry returns last regular entry (ignoring undoed ones) for the given ref (or current ref if not specified).

func (*Logger) GetLogPath

func (l *Logger) GetLogPath() string

GetLogPath returns the path to the log file.

func (*Logger) LogCommand

func (l *Logger) LogCommand(strGitCommand string) error

LogCommand logs a git command with timestamp.

func (*Logger) ToggleEntry

func (l *Logger) ToggleEntry(entryIdentifier string) error

ToggleEntry toggles the undo state of an entry by adding or removing the "#" prefix. The entryIdentifier should be in the format "TIMESTAMP|REF|COMMAND" (without the # prefix). Returns true if the entry was marked as undoed, false if it was unmarked.

Jump to

Keyboard shortcuts

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