logging

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

logging tails a log file in real time, sending new lines to a channel with exponential backoff when waiting for new data.

Log entry types and paginated querying. Reads the log file backwards so the most recent entries come first.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MarshalLokiBatch added in v1.5.0

func MarshalLokiBatch(batch LokiBatch) ([]byte, error)

func SendLokiTestEntry added in v1.5.0

func SendLokiTestEntry(endpoint, bearerToken, tenantID string) error

func TailFile

func TailFile(ctx context.Context, path string, lines chan<- string) error

Types

type LogEntry

type LogEntry struct {
	Level   string      `json:"level"`
	Ts      float64     `json:"ts"`
	Logger  string      `json:"logger"`
	Msg     string      `json:"msg"`
	Request *LogRequest `json:"request,omitempty"`

	Duration    float64             `json:"duration,omitempty"`
	Status      int                 `json:"status,omitempty"`
	Size        int                 `json:"size,omitempty"`
	RespHeaders map[string][]string `json:"resp_headers,omitempty"`

	Extra map[string]any `json:"extra,omitempty"`
}

func (*LogEntry) UnmarshalJSON

func (e *LogEntry) UnmarshalJSON(data []byte) error

type LogRequest

type LogRequest struct {
	RemoteAddr string              `json:"remote_addr"`
	Proto      string              `json:"proto"`
	Method     string              `json:"method"`
	Host       string              `json:"host"`
	URI        string              `json:"uri"`
	Headers    map[string][]string `json:"headers,omitempty"`
	TLS        *LogTLS             `json:"tls,omitempty"`
}

type LogTLS

type LogTLS struct {
	Resumed     bool   `json:"resumed"`
	Version     int    `json:"version"`
	CipherSuite int    `json:"cipher_suite"`
	Proto       string `json:"proto"`
	ServerName  string `json:"server_name"`
}

type LokiBatch added in v1.5.0

type LokiBatch struct {
	Streams []LokiStream
}

type LokiBatcher added in v1.5.0

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

func NewLokiBatcher added in v1.5.0

func NewLokiBatcher(
	lines <-chan TaggedLine,
	batches chan<- LokiBatch,
	batchSize int,
	flushInterval time.Duration,
	staticLabels map[string]string,
) *LokiBatcher

func (*LokiBatcher) Run added in v1.5.0

func (b *LokiBatcher) Run(ctx context.Context)

type LokiEntry added in v1.5.0

type LokiEntry struct {
	Timestamp string
	Line      string
}

type LokiPipeline added in v1.5.0

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

func NewLokiPipeline added in v1.5.0

func NewLokiPipeline(store *config.ConfigStore, positionsPath string, resolveSinks SinkResolver) *LokiPipeline

func (*LokiPipeline) GetPusher added in v1.5.0

func (p *LokiPipeline) GetPusher() *LokiPusher

func (*LokiPipeline) GetStatus added in v1.5.0

func (p *LokiPipeline) GetStatus() (bool, map[string]SinkStatus)

func (*LokiPipeline) GetTailerNames added in v1.6.0

func (p *LokiPipeline) GetTailerNames() []string

func (*LokiPipeline) IsRunning added in v1.5.0

func (p *LokiPipeline) IsRunning() bool

func (*LokiPipeline) Reconfigure added in v1.5.0

func (p *LokiPipeline) Reconfigure()

func (*LokiPipeline) Restart added in v1.5.0

func (p *LokiPipeline) Restart()

func (*LokiPipeline) Start added in v1.5.0

func (p *LokiPipeline) Start()

func (*LokiPipeline) Stop added in v1.5.0

func (p *LokiPipeline) Stop()

type LokiPusher added in v1.5.0

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

func NewLokiPusher added in v1.5.0

func NewLokiPusher(
	endpoint, bearerToken, tenantID string,
	batches <-chan LokiBatch,
) *LokiPusher

func (*LokiPusher) GetStatus added in v1.5.0

func (p *LokiPusher) GetStatus() map[string]SinkStatus

func (*LokiPusher) Run added in v1.5.0

func (p *LokiPusher) Run(ctx context.Context)

type LokiStream added in v1.5.0

type LokiStream struct {
	Labels  map[string]string
	Entries []LokiEntry
}

type LokiTailer added in v1.5.0

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

func NewLokiTailer added in v1.5.0

func NewLokiTailer(sink, path string, pos *PositionStore, lines chan<- TaggedLine) *LokiTailer

func (*LokiTailer) Run added in v1.5.0

func (t *LokiTailer) Run(ctx context.Context)

type PositionStore added in v1.5.0

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

func NewPositionStore added in v1.5.0

func NewPositionStore(path string) *PositionStore

func (*PositionStore) Cleanup added in v1.5.0

func (ps *PositionStore) Cleanup(activePaths map[string]bool)

func (*PositionStore) Get added in v1.5.0

func (ps *PositionStore) Get(path string) int64

func (*PositionStore) Load added in v1.5.0

func (ps *PositionStore) Load() error

func (*PositionStore) Remove added in v1.5.0

func (ps *PositionStore) Remove(path string)

func (*PositionStore) Save added in v1.5.0

func (ps *PositionStore) Save() error

func (*PositionStore) Set added in v1.5.0

func (ps *PositionStore) Set(path string, offset int64)

type QueryParams

type QueryParams struct {
	Limit     int
	Offset    int
	Level     string
	Host      string
	StatusMin int
	StatusMax int
	Since     time.Time
	Until     time.Time
}

type QueryResult

type QueryResult struct {
	Entries []LogEntry `json:"entries"`
	HasMore bool       `json:"has_more"`
}

func QueryLogs

func QueryLogs(path string, params QueryParams) (*QueryResult, error)

type SinkResolver added in v1.5.0

type SinkResolver func() map[string]string

type SinkStatus added in v1.5.0

type SinkStatus struct {
	Tailing       bool      `json:"tailing"`
	LastPushAt    time.Time `json:"last_push_at"`
	EntriesPushed int64     `json:"entries_pushed"`
	LastError     string    `json:"last_error"`
}

type TaggedLine added in v1.5.0

type TaggedLine struct {
	Sink string
	Line string
}

Jump to

Keyboard shortcuts

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