kmsg

package
v0.9.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2021 License: MPL-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package kmsg provides access to kernel log.

nolint: dupl

Index

Constants

View Source
const MaxLineLength = 1024 - 48

MaxLineLength to be passed to kmsg, see https://github.com/torvalds/linux/blob/master/kernel/printk/printk.c#L450.

Variables

This section is empty.

Functions

func SetupLogger added in v0.5.0

func SetupLogger(logger *log.Logger, prefix string, extraWriter io.Writer) error

SetupLogger configures the logger to write to the kernel ring buffer via /dev/kmsg.

If logger is nil, default `log` logger is redirectred.

If extraWriter is not nil, logs will be copied to it as well.

Types

type Facility added in v0.3.0

type Facility int

Facility is an attribute of kernel log message.

const (
	Kern Facility = iota
	User
	Mail
	Daemon
	Auth
	Syslog
	Lpr
	News
	Uucp
	Cron
	AuthPriv
	Local0
	Local1
	Local2
	Local3
	Local4
	Local5
	Local6
	Local7
)

Kernel log facilities.

From <sys/syslog.h>.

func (Facility) String added in v0.3.0

func (f Facility) String() string

type Message added in v0.3.0

type Message struct {
	Facility       Facility
	Priority       Priority
	SequenceNumber int64
	Clock          int64
	Timestamp      time.Time
	Message        string
}

Message is a parsed kernel log message.

func ParseMessage added in v0.3.0

func ParseMessage(input string, bootTime time.Time) (Message, error)

ParseMessage parses internal kernel log format.

Reference: https://www.kernel.org/doc/Documentation/ABI/testing/dev-kmsg

type Option added in v0.3.0

type Option func(*options)

Option configures Reader.

func Follow added in v0.3.0

func Follow() Option

Follow the kmsg to stream live messages.

func FromTail added in v0.3.0

func FromTail() Option

FromTail starts reading kmsg from the tail (after last message).

type Packet added in v0.3.0

type Packet struct {
	Message Message
	Err     error
}

Packet combines Message and error.

Only one of the fields is set in Reader.Scan.

type Priority added in v0.3.0

type Priority int

Priority is an attribute of kernel log message.

const (
	Emerg Priority = iota
	Alert
	Crit
	Err
	Warning
	Notice
	Info
	Debug
)

Kernel log priorities.

func (Priority) String added in v0.3.0

func (p Priority) String() string

type Reader added in v0.3.0

type Reader interface {
	// Scan and issue parsed messages.
	//
	// Scan stops when context is canceled or when EOF is reached
	// in NoFollow mode.
	Scan(ctx context.Context) <-chan Packet

	// Close releases resources associated with the Reader.
	Close() error
}

Reader for /dev/kmsg messages.

func NewReader added in v0.3.0

func NewReader(options ...Option) (Reader, error)

NewReader initializes new /dev/kmsg reader.

type Writer added in v0.4.0

type Writer struct {
	KmsgWriter io.Writer
}

Writer ensures writes by line and limits each line to maxLineLength characters.

This workarounds kmsg limits.

func (*Writer) Write added in v0.4.0

func (w *Writer) Write(p []byte) (n int, err error)

Write implements io.Writer interface.

Jump to

Keyboard shortcuts

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