Documentation
¶
Overview ¶
Package logparser parses logs.
Index ¶
- Constants
- func DeduceNanos(n int64) (int64, bool)
- func DeduceSeverity(text string) plog.SeverityNumber
- func ParseSpanID[S ~string | ~[]byte](s S) (spanID otelstorage.SpanID, _ bool)
- func ParseTimestamp(s []byte) (otelstorage.Timestamp, bool)
- func ParseTraceID(s string) (otelstorage.TraceID, bool)
- func RegisterFormat(f string, p Parser)
- type GenericJSONParser
- type KLogParser
- type LogFmtParser
- type Parser
- type Record
- type Source
- type UnixTimestampKind
- type ZapDevelopmentParser
Constants ¶
const ( UnixUnknown = UnixTimestampKind(0) UnixNano = UnixTimestampKind(time.Nanosecond) UnixMicro = UnixTimestampKind(time.Microsecond) UnixMilli = UnixTimestampKind(time.Millisecond) Unix = UnixTimestampKind(time.Second) )
const ISO8601Millis = "2006-01-02T15:04:05.000Z0700"
ISO8601Millis time format with millisecond precision.
Variables ¶
This section is empty.
Functions ¶
func DeduceNanos ¶
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 ¶
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.
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) HandleLogfmt ¶
type Source ¶
Source locates source code produced the log record.
func ParseSource ¶
ParseSource parses source location.
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.
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