package logparse
import "k8s.io/kubernetes/cmd/prune-junit-xml/logparse"
Package logparse provides a parser for the klog text format:
I1007 13:16:55.727802 1146763 example.go:57] "Key/value encoding" logger="example" foo="bar" duration="1s" int=42 float=3.14 string="hello world" quotedString="hello \"world\"" multiLinString=< hello world > E1007 15:20:04.343375 1157755 example.go:41] Log using Errorf, err: fail
It also supports the klog/ktesting unit test log output:
=== RUN TestKlogr example_test.go:45: I1007 13:28:21.908998] hello world example_test.go:46: E1007 13:28:21.909034] failed err="failed: some error" example_test.go:47: I1007 13:28:21.909042] verbosity 1 example_test.go:48: I1007 13:28:21.909047] main/helper: with prefix example_test.go:50: I1007 13:28:21.909076] key/value pairs int=1 float=2 pair="(1, 2)" raw={"Name":"joe","NS":"kube-system"} slice=[1,2,3,"str"] map={"a":1,"b":2} kobj="kube-system/joe" string="hello world" quotedString="hello \"world\"" multiLineString=< hello world > example_test.go:63: I1007 13:28:21.909085] info message level 4 example_test.go:64: I1007 13:28:21.909089] info message level 5 --- PASS: TestKlogr (0.00s) PASS ok k8s.io/klog/v2/ktesting/example (cached)
Arbitrary indention with space or tab is supported. All lines of a klog log entry must be indented the same way.
Index ¶
- Constants
- func All(in io.Reader) iter.Seq[Entry]
- type Entry
- type ErrorEntry
- type KlogEntry
- type OtherEntry
- type Severity
Constants ¶
const ( SeverityInfo = Severity('I') SeverityWarning = Severity('W') SeverityError = Severity('E') SeverityFatal = Severity('F') )
Functions ¶
func All ¶
All is like Parse except that it can be used in a for/range loop:
for entry := range logparse.All(reader) { // entry is the next log entry. }
Types ¶
type Entry ¶
type Entry interface { // LogData returns a verbatim copy of the original log chunk, // including one or more line breaks. Concatenating these chunks // from all entries will reconstruct the parsed log. LogData() string }
Entry is the base type for a log entry.
Use type assertions to check for additional information. All of the instances behind this interface are pointers.
func Parse ¶
Parse splits log output provided by the reader into individual log entries. The original log can be reconstructed verbatim by concatenating these entries. If the reader fails with an error, the last log entry will capture that error.
type ErrorEntry ¶
type ErrorEntry struct { Err error }
ErrorEntry captures the error encountered while reading the log input.
func (*ErrorEntry) LogData ¶
func (e *ErrorEntry) LogData() string
func (*ErrorEntry) String ¶
func (e *ErrorEntry) String() string
type KlogEntry ¶
LogEntry captures some log entry which was recognized as coming from klog.
func (*KlogEntry) LogData ¶
func (*KlogEntry) String ¶
type OtherEntry ¶
type OtherEntry struct { Data string }
OtherEntry captures some log line which is not part of a klog log entry.
func (*OtherEntry) LogData ¶
func (e *OtherEntry) LogData() string
func (*OtherEntry) String ¶
func (e *OtherEntry) String() string
type Severity ¶
type Severity byte
Source Files ¶
logparse.go
- Version
- v1.33.0 (latest)
- Published
- Apr 23, 2025
- Platform
- linux/amd64
- Imports
- 7 packages
- Last checked
- 3 hours ago –
Tools for package owners.