dateparser

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KlogRegex     = `\d{4} \d{2}:\d{2}:\d{2}.\d{6}`
	EtcdRegex     = `"ts":"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z"`
	RancherRegex  = `^\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}`
	JournaldRegex = `^[A-Z][a-z]{2} \d{1,2} \d{2}:\d{2}:\d{2}`

	RancherLayout  = "2006/01/02 15:04:05"
	KlogLayout     = "0102 15:04:05.999999 MST 2006"
	JournaldLayout = "Jan 02 15:04:05 MST 2006"
)
View Source
const (
	EtcdTimestampRegex  = `^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{6}`
	EtcdTimestampLayout = "2006-01-02 15:04:05.999999Z07:00"
	RFC3339Milli        = "2006-01-02T15:04:05.999Z07:00"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DateParser

type DateParser interface {
	ParseTimestamp(log string) (time.Time, string, bool) // Parse timestamp should have the implementation for parsing the timestamp from a log line
}

DateParser is an interface for parsing the timestamp from a log line It returns the datetime, the log line, and a boolean indicating if the datetime was found

func NewDayMonthParser

func NewDayMonthParser(datetimeRegex string, layout string, opts ...DayMonthOption) DateParser

type Dateformat

type Dateformat struct {
	DateRegex  string
	Layout     string
	DateSuffix string
}

type DayMonthOption

type DayMonthOption func(*dayMonthOptions)

func WithInnerDateRegex

func WithInnerDateRegex(regex string) DayMonthOption

func WithStripOuterDate

func WithStripOuterDate() DayMonthOption

func WithTimezone

func WithTimezone(timezone string) DayMonthOption

func WithYear

func WithYear(year string) DayMonthOption

type DayMonthParser

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

DayMonthParser will parse a timestamp string without a year and timezone into a datetime given the regex and layout of the timestamp. It will also optionally strip the outer date and detect if the remaining text contains a valid date

func (*DayMonthParser) ParseTimestamp

func (d *DayMonthParser) ParseTimestamp(log string) (time.Time, string, bool)

type DockerParser

type DockerParser struct {
	TimestampRegex string
}

DockerParser will parse logs with a default ISO8601 timestamp. It is expected that there will be two timestamps

func (*DockerParser) ParseTimestamp

func (p *DockerParser) ParseTimestamp(log string) (time.Time, string, bool)

type EtcdJSONLog

type EtcdJSONLog struct {
	LogLevel  string `json:"level,omitempty"`
	Timestamp string `json:"ts,omitempty"`
	Message   string `json:"msg,omitempty"`
}

type LogType

type LogType string
const (
	LogTypeControlplane LogType = "controlplane"
	LogTypeRancher      LogType = "rancher"
)

type MultipleParser

type MultipleParser struct {
	Dateformats      []Dateformat
	StripLeadingDate bool
}

Multiple parser will parse logs with multiple date formats and optionally strip the leading date.

func (*MultipleParser) ParseTimestamp

func (p *MultipleParser) ParseTimestamp(log string) (time.Time, string, bool)

type RKE2EtcdParser

type RKE2EtcdParser struct{}

RKE2EtcdParser will parse etcd logs for RKE2. These logs can either be in json or plain text.

func (RKE2EtcdParser) ParseTimestamp

func (r RKE2EtcdParser) ParseTimestamp(log string) (time.Time, string, bool)

Jump to

Keyboard shortcuts

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