logs

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: Apache-2.0 Imports: 7 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 logs parses captured container log lines into structured records and evaluates the Flightbay log query language.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContainsFold

func ContainsFold(s, lower string) bool

ContainsFold reports whether s contains the lower-case needle, ignoring ASCII case, without allocating. Searches run over every captured line, so lower-casing each line per query (the obvious way) costs gigabytes of garbage on a large bundle.

func NormalizeLevel

func NormalizeLevel(l string) string

NormalizeLevel maps the many level spellings onto trace, debug, info, warn, error.

func Signature

func Signature(msg string) string

Signature collapses variable parts so similar errors group together.

func SortNewestFirst

func SortNewestFirst(rs []*Record)

SortNewestFirst orders records by time, newest first, keeping line order stable.

func SplitTimestamp

func SplitTimestamp(line string) (time.Time, string)

SplitTimestamp removes the RFC 3339 timestamp the kubelet adds with timestamps=true.

func Tokenize

func Tokenize(s string) ([]string, error)

Tokenize splits a query on spaces, keeping quoted phrases together.

Types

type Fields

type Fields []string

Fields are parsed key/value pairs, stored as a sorted flat slice (k0, v0, k1, v1...). A map per line costs several hundred bytes; most lines have a handful of fields.

func NewFields

func NewFields(m map[string]string) Fields

NewFields converts a parsed map.

func (Fields) Get

func (f Fields) Get(k string) (string, bool)

Get returns a field's value.

func (Fields) Map

func (f Fields) Map() map[string]string

Map returns the fields as a map.

func (Fields) MarshalJSON

func (f Fields) MarshalJSON() ([]byte, error)

MarshalJSON writes the fields as a JSON object.

func (*Fields) UnmarshalJSON

func (f *Fields) UnmarshalJSON(b []byte) error

UnmarshalJSON reads a JSON object.

type Parsed

type Parsed struct {
	Level, Scope, Msg string
	Fields            map[string]string
}

Parsed is the structured view of a line.

func Parse

func Parse(line string) Parsed

Parse sniffs the format: JSON, istio/ztunnel text, Envoy access log, klog, logfmt, then raw.

type Query

type Query struct {
	Text string

	Since     time.Duration
	Reference time.Time // "now" for since:, normally the end of the capture
	// contains filtered or unexported fields
}

Query is a parsed log query. Terms are ANDed; OR joins neighbours.

func ParseQuery

func ParseQuery(s string) (*Query, error)

ParseQuery parses level:error ns:payments pod:checkout* trace_id:x "phrase" -term since:15m.

func (*Query) Match

func (q *Query) Match(r *Record) bool

Match reports whether a record satisfies the query.

func (*Query) SQL

func (q *Query) SQL(ref time.Time) (string, []any)

SQL translates the query into a DuckDB WHERE clause over the log_lines table (ts is Unix nanoseconds). ref is "now" for since:. The same query language drives the in-memory matcher and SQL, and a test keeps them equal.

type Record

type Record struct {
	ID  int64     `json:"id"`
	Seq int       `json:"seq"`
	TS  time.Time `json:"ts"`
	*Source
	Level  string `json:"level"`
	Scope  string `json:"scope,omitempty"`
	Msg    string `json:"msg"`
	Fields Fields `json:"fields,omitempty"`
	Raw    string `json:"raw"`
}

Record is one parsed log line. Source is embedded, so r.Pod and the JSON shape are unchanged.

type Source

type Source struct {
	Cluster   string `json:"cluster"`
	Namespace string `json:"namespace"`
	Pod       string `json:"pod"`
	Container string `json:"container"`
	Stream    string `json:"stream"`
	Node      string `json:"node,omitempty"`
	// Workload is the Deployment, DaemonSet, StatefulSet, Job (or bare pod)
	// the pod belongs to, so a controller's logs can be read across pods.
	Workload     string `json:"workload,omitempty"`
	WorkloadKind string `json:"workloadKind,omitempty"`
	Chunk        string `json:"-"`
}

Source is where a line came from. Every line of a log chunk shares one, so the identity strings are stored once per chunk rather than once per line.

Jump to

Keyboard shortcuts

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