logparser

package
v0.42.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package logparser parses logs.

Index

Constants

View Source
const ISO8601Millis = "2006-01-02T15:04:05.000Z0700"

ISO8601Millis time format with millisecond precision.

Variables

This section is empty.

Functions

func DeduceNanos

func DeduceNanos(n int64) (int64, bool)

DeduceNanos returns unix nano from arbitrary time integer, deducing resolution by range.

func DeduceSeverity

func DeduceSeverity(text string) plog.SeverityNumber

DeduceSeverity deduces severity from given level.

func ParseSpanID

func ParseSpanID[S ~string | ~[]byte](s S) (spanID otelstorage.SpanID, _ bool)

ParseSpanID tries its best to parse span ID.

func ParseTimestamp

func ParseTimestamp(s []byte) (otelstorage.Timestamp, bool)

ParseTimestamp tries its best to parse a timestamp.

func ParseTraceID

func ParseTraceID(s string) (otelstorage.TraceID, bool)

ParseTraceID tries its best to parse trace ID.

func RegisterFormat

func RegisterFormat(f string, p Parser)

RegisterFormat register a Parser for specified format name.

Types

type GenericJSONParser

type GenericJSONParser struct{}

GenericJSONParser can parse generic json into [Line].

func (GenericJSONParser) Detect

func (GenericJSONParser) Detect(line string) bool

Detect if line is parsable by this parser.

func (GenericJSONParser) Parse

func (GenericJSONParser) Parse(data string, target *Record) error

Parse generic json into [Line].

func (GenericJSONParser) String

func (GenericJSONParser) String() string

type KLogParser

type KLogParser struct{}

KLogParser can parse klog record into [Line].

func (KLogParser) Detect

func (KLogParser) Detect(line string) bool

Detect if line is parsable by this parser.

func (KLogParser) Parse

func (KLogParser) Parse(data string, target *Record) error

Parse klog line into [Line].

func (KLogParser) String

func (KLogParser) String() string

type LogFmtParser

type LogFmtParser struct{}

LogFmtParser parses logfmt lines.

func (LogFmtParser) Detect

func (LogFmtParser) Detect(line string) bool

Detect if line is parsable by this parser.

func (LogFmtParser) Parse

func (LogFmtParser) Parse(data string, target *Record) error

Parse line.

func (LogFmtParser) String

func (LogFmtParser) String() string

type Parser

type Parser interface {
	// Parse parses data and returns a line.
	//
	// TODO: refactor to `Parse(data []byte, target *logstorage.Record) error`
	Parse(data string, target *Record) error
	// Detect whether data is parsable.
	//
	// TODO: refactor to `Detect(data []byte) bool`
	Detect(line string) bool
	String() string
}

Parser parses logs.

func LookupFormat

func LookupFormat(f string) (Parser, bool)

LookupFormat returns a Parser instance for specified format name.

type Record

type Record struct {
	Timestamp         otelstorage.Timestamp `json:"timestamp"`
	ObservedTimestamp otelstorage.Timestamp `json:"observed_timestamp"`
	TraceID           otelstorage.TraceID   `json:"trace_id"`
	SpanID            otelstorage.SpanID    `json:"span_id"`
	Flags             plog.LogRecordFlags   `json:"flags"`
	SeverityText      string                `json:"severity_text"`
	SeverityNumber    plog.SeverityNumber   `json:"severity_number"`
	Body              string                `json:"body"`
	Attrs             otelstorage.Attrs     `json:"attrs"`

	ResourceAttrs otelstorage.Attrs `json:"resource_attrs"`

	ScopeName    string            `json:"scope_name"`
	ScopeVersion string            `json:"scope_version"`
	ScopeAttrs   otelstorage.Attrs `json:"scope_attrs"`
}

Record is a log record.

func (Record) Encode

func (r Record) Encode(e *jx.Encoder)

Encode line as json.

func (*Record) HandleLogfmt

func (r *Record) HandleLogfmt(key, val []byte) error

func (*Record) Reset

func (r *Record) Reset()

Reset resets fields.

func (Record) String

func (r Record) String() string

String implements fmt.Stringer.

type Source

type Source struct {
	Filename string
	Line     int
	Column   int
}

Source locates source code produced the log record.

func ParseSource

func ParseSource(s string) (src Source, _ error)

ParseSource parses source location.

func (*Source) Add

func (s *Source) Add(m pcommon.Map) bool

Add adds fields as attributes to given set.

type UnixTimestampKind

type UnixTimestampKind int64

UnixTimestampKind determines kind of unix timestamp.

func DeduceUnixTimestampKind

func DeduceUnixTimestampKind(n int64) (UnixTimestampKind, bool)

DeduceUnixTimestampKind deduces Unix timestamp kind.

func (UnixTimestampKind) FloatNanos

func (k UnixTimestampKind) FloatNanos(integer, frac float64) (int64, bool)

FloatNanos converts floating point timestamp of kind k to nanosecond timestamp.

func (UnixTimestampKind) Nanos

func (k UnixTimestampKind) Nanos(ts int64) (int64, bool)

Nanos converts timestamp of kind k to nanosecond timestamp.

type ZapDevelopmentParser

type ZapDevelopmentParser struct{}

ZapDevelopmentParser parses zap's development mode lines.

func (ZapDevelopmentParser) Detect

func (ZapDevelopmentParser) Detect(line string) bool

Detect if line is parsable by this parser.

func (ZapDevelopmentParser) Parse

func (ZapDevelopmentParser) Parse(data string, target *Record) error

Parse line.

func (ZapDevelopmentParser) String

func (ZapDevelopmentParser) String() string

Jump to

Keyboard shortcuts

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