kmsgparser

package
v3.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2023 License: Apache-2.0 Imports: 9 Imported by: 2

Documentation

Overview

Package kmsgparser implements a parser for the Linux `/dev/kmsg` format. More information about this format may be found here: https://www.kernel.org/doc/Documentation/ABI/testing/dev-kmsg Some parts of it are slightly inspired by rsyslog's contrib module: https://github.com/rsyslog/rsyslog/blob/v8.22.0/contrib/imkmsg/kmsg.c

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithLogger

func WithLogger(log Logger) func(p *parser)

WithLogger configures the Parser's Logger

func WithNoFollow

func WithNoFollow() func(p *parser)

WithNoFollow configures Parser to stop reading and close the channel when it reaches the end of the kmsg buffer.

Types

type Logger

type Logger interface {
	Warningf(string, ...interface{})
	Infof(string, ...interface{})
	Errorf(string, ...interface{})
}

Logger is a glog compatible logging interface The StandardLogger struct can be used to convert a log.Logger into this interface.

type Message

type Message struct {
	Priority       int
	SequenceNumber int
	Timestamp      time.Time
	Message        string
}

Message represents a given kmsg logline, including its timestamp (as calculated based on offset from boot time), its possibly multi-line body, and so on. More information about these mssages may be found here: https://www.kernel.org/doc/Documentation/ABI/testing/dev-kmsg

type Option

type Option func(p *parser)

Option is a configuration option for NewParser

type Parser

type Parser interface {
	// SeekEnd moves the parser to the end of the kmsg queue.
	SeekEnd() error
	// Parse reads from kmsg and provides a channel of messages.
	// Parse will always close the provided channel before returning.
	// Parse may be canceled by calling 'Close' on the parser.
	//
	// The caller should drain the channel after calling [Close]. The caller must
	// not close the channel passed in.
	Parse(chan<- Message) error

	Close() error
}

Parser is a parser for the kernel ring buffer found at /dev/kmsg

func NewParser

func NewParser(opts ...Option) (Parser, error)

NewParser constructs a new parser with the given Options.

type StandardLogger

type StandardLogger struct {
	*stdlog.Logger
}

StandardLogger adapts the log.Logger interface to be a Logger.

func (*StandardLogger) Errorf

func (s *StandardLogger) Errorf(fmt string, args ...interface{})

func (*StandardLogger) Infof

func (s *StandardLogger) Infof(fmt string, args ...interface{})

func (*StandardLogger) Warningf

func (s *StandardLogger) Warningf(fmt string, args ...interface{})

Jump to

Keyboard shortcuts

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