kmsg

package module
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2024 License: MPL-2.0 Imports: 13 Imported by: 1

README

go-kmsg

Go library to interact with Linux kernel message buffer.

Documentation

Overview

Package kmsg provides access to kernel log.

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

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

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

func (f Facility) String() string

type Message

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

Message is a parsed kernel log message.

func ParseMessage

func ParseMessage(input []byte, bootTime time.Time) (Message, error)

ParseMessage parses internal kernel log format.

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

type Option

type Option func(*options)

Option configures Reader.

func Follow

func Follow() Option

Follow the kmsg to stream live messages.

func FromTail

func FromTail() Option

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

type Packet

type Packet struct {
	Err     error
	Message Message
}

Packet combines Message and error.

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

type Priority

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

func (p Priority) String() string

type Reader

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

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

NewReader initializes new /dev/kmsg reader.

type Writer

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

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