logwhale

package module
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2023 License: MIT Imports: 11 Imported by: 0

README

logwhale

This project started life as a way to consume a single newline terminated structured log file and stream the contents to a consumer. After discovering the usual problem with early termination on EOF, I decided to add a few more features.

Though it was originally designed to consume a single file, it can now follow any number of files and will continue to wait for data until stopped or the files are removed.

Numerous edge cases exist but the aim is to make this as robust as possible. If you find a bug, please raise an issue

Features

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorState

type ErrorState int

ErrorState defines a set of concrete error states that can be encountered by the LogManager.

const (
	ErrorStateUnknown ErrorState = iota
	ErrorStateCancelled
	ErrorStateFSWatcher
	ErrorStateFilePath
	ErrorStateFileNotExist
	ErrorStateFileRemoved
	ErrorStateFileIO
	ErrorStateEndOfStream
	ErrorStateInternal
)

func (ErrorState) String

func (es ErrorState) String() string

String() returns a string representation of the ErrorState.

type LogManager

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

LogManager is used to watch one of more log files for changes and consume the data line by line to be passed as a byte slice to a consumer channel.

func NewLogManager

func NewLogManager(ctx context.Context, options ...Option) (*LogManager, error)

NewLogManager creates a new LogManager

func (*LogManager) AddLogFile

func (lm *LogManager) AddLogFile(lp string) (<-chan []byte, <-chan error, error)

AddLogFile adds a log file to the LogManager and starts its data processor. Two channels are returned, for data and errors respectively and an error if the Add operation fails completely.

The data channel will return a byte slice for each delimited line of the log file. The default delimeter is a newline.

The error channel will return any errors encountered while processing the log file which can be both critical and non-critical. When a critical error is encountered, the data processor will stop and the log file will be removed from the LogManager. Non-critical errors will be logged and the data processor will continue. Both channels will be closed when all operations have completed or critical errors have been encountered.

func (*LogManager) Close

func (lm *LogManager) Close() error

Close closes the LogManager.

func (*LogManager) GetLogFile

func (lm *LogManager) GetLogFile(fp string) (<-chan []byte, <-chan error, error)

GetLogFile returns the data and error channels for a log file being watched by the LogManager.

func (*LogManager) GetLogFiles

func (lm *LogManager) GetLogFiles() []string

GetLogFiles returns a slice of log file paths being watched by the LogManager.

func (*LogManager) RemoveLogFile

func (lm *LogManager) RemoveLogFile(lp string) error

RemoveLogFile removes a log file from the LogManager and stops its data processor.

type LogWhaleError

type LogWhaleError struct {
	State ErrorState
	Msg   string
	Cause error
}

func NewLogWhaleError

func NewLogWhaleError(state ErrorState, msg string, cause error) *LogWhaleError

func (*LogWhaleError) Error

func (e *LogWhaleError) Error() string

Error satisfies the error interface.

func (*LogWhaleError) Unwrap

func (e *LogWhaleError) Unwrap() error

Unwrap satisfies the Wrapper interface. It allows the LogWhaleError to work with and errors.As.

type Option

type Option func(*LogManager) error

Option is a function that can be passed to NewLogManager to configure it.

func WithBufferSize

func WithBufferSize(bs int) Option

Jump to

Keyboard shortcuts

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