lognorm

package
v1.5.11 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 9 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 lognorm turns raw container log lines into clusterable records: it picks the useful JSON fields, joins stack traces and masks variable parts. All functions are pure; nothing here touches the store or the API.

Index

Constants

View Source
const (
	PhTimestamp = "<TS>"
	PhUUID      = "<UUID>"
	PhIP        = "<IP>"
	PhHex       = "<HEX>"
	PhNum       = "<NUM>"
)

Placeholders left in a template so equal failures with different values cluster.

View Source
const (
	MaxStackLines  = 64
	MaxRecordBytes = 8192
)

Caps for one joined record. Package constants until the wiring slice makes them runtime settings.

View Source
const DefaultMaxClusters = 200

DefaultMaxClusters is the per-stream cap until the logs.miner_max_clusters runtime setting is wired (needs design: the miner has no caller yet).

View Source
const DefaultSimilarity = 0.5

DefaultSimilarity is the share of equal tokens a line needs to join a cluster.

View Source
const Wildcard = "<*>"

Wildcard marks a token position that differed across lines of one cluster.

Variables

This section is empty.

Functions

func Join

func Join(lines []string) []string

Join folds Go, Java, Python and Node stack traces into single multi-line records and passes every other line through untouched.

func MaskPatterns

func MaskPatterns(s string) string

MaskPatterns replaces credential-shaped text with the secretmask marker.

func Placeholders

func Placeholders(s string) string

Placeholders swaps timestamps, uuids, ips, hex ids and numbers for tokens.

func Sample

func Sample(line string, reg *secretmask.Registry) string

Sample returns the line with known secrets and credential shapes masked. This is the only form that may be stored; reg nil uses the process-wide registry.

func Scrub

func Scrub(s string) string

Scrub applies the process-wide registry and then the pattern pass, for text that is about to leave the process.

func Template

func Template(line string, reg *secretmask.Registry) string

Template masks secrets first, then replaces variable parts with placeholders.

Types

type Entry

type Entry struct {
	Sample   string
	Template string
	Level    string
}

Entry is one normalized record ready for a miner.

func Normalize

func Normalize(lines []string, reg *secretmask.Registry) []Entry

Normalize runs join, field pick and mask over raw lines in order.

type MinedTemplate

type MinedTemplate struct {
	ID       string
	Template string
	Count    int
	Sample   string
}

MinedTemplate is one mined cluster: a stable id, how many lines it absorbed and a masked sample line.

type Miner

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

Miner is a small Drain-style clusterer: lines group by token count and first token, then merge with the closest cluster above the similarity bar. It is not safe for concurrent use; one miner per stream.

func NewMiner

func NewMiner(cfg MinerConfig) *Miner

NewMiner returns an empty miner.

func (*Miner) Add

func (m *Miner) Add(e Entry)

Add feeds one normalized entry. The entry sample is already secret-masked, and the template carries placeholders only, so nothing raw is retained.

func (*Miner) AddAll

func (m *Miner) AddAll(entries []Entry)

AddAll feeds a batch in order.

func (*Miner) Templates

func (m *Miner) Templates() []MinedTemplate

Templates returns clusters by descending count, then template text.

type MinerConfig

type MinerConfig struct {
	MaxClusters int
	Similarity  float64
}

MinerConfig bounds one stream's miner. Zero values fall back to the defaults.

type Record

type Record struct {
	Message    string
	Level      string
	Error      string
	Structured bool
}

Record is one logical log entry after field picking.

func Extract

func Extract(line string) Record

Extract picks message, level and error from a JSON log line. A line that is not a JSON object comes back unchanged as the message.

func (Record) Text

func (r Record) Text() string

Text renders the record as one line suitable for clustering.

Jump to

Keyboard shortcuts

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