ulog

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2020 License: BSD-3-Clause Imports: 5 Imported by: 101

Documentation

Overview

Package ulog exposes logging via a Go interface.

ulog has three implementations of the Logger interface: a Go standard library "log" package Logger, a kernel syslog (dmesg) Logger, and a test Logger that logs via a test's testing.TB.Logf. To use the test logger import "ulog/ulogtest".

Index

Constants

This section is empty.

Variables

View Source
var KernelLog = &KLog{
	LogLevel: uintptr(KLogInfo),
}

KernelLog is a logger that prints to the kernel syslog buffer.

Default log level is KLogInfo.

If the syslog buffer cannot be written to, KernelLog falls back to Log.

Functions

This section is empty.

Types

type KLog

type KLog struct {
	// FD for /dev/kmsg if it was openable.
	*os.File

	// LogLevel is the LogLevel to print with.
	//
	// Should only be accessed atomically.
	LogLevel uintptr
}

KLog is a logger to the kernel syslog buffer.

func (*KLog) ClearLog

func (k *KLog) ClearLog() error

ClearLog clears kernel logs back to empty.

func (*KLog) Print

func (k *KLog) Print(v ...interface{})

Print formats using the default operands for v and writes to kernel logging.

func (*KLog) Printf

func (k *KLog) Printf(format string, v ...interface{})

Printf formats according to a format specifier and writes to kernel logging.

func (*KLog) Read

func (k *KLog) Read(b []byte) (int, error)

Read reads from the tail of the kernel log.

func (*KLog) ReadClear

func (k *KLog) ReadClear(b []byte) (int, error)

ReadClear reads from the tail of the kernel log and clears what was read.

func (*KLog) Reinit

func (k *KLog) Reinit()

Reinit reopens the /dev/kmsg file.

func (*KLog) SetConsoleLogLevel

func (k *KLog) SetConsoleLogLevel(level KLogLevel) error

SetConsoleLogLevel sets the console level with syslog(2).

After this call, only messages with a level value lower than the one specified will be printed to console by the kernel.

func (*KLog) SetLogLevel

func (k *KLog) SetLogLevel(level KLogLevel)

SetLogLevel sets the level that Printf and Print log to syslog with.

type KLogLevel

type KLogLevel uintptr

KLogLevel are the log levels used by printk.

const (
	KLogEmergency KLogLevel = 0
	KLogAlert     KLogLevel = 1
	KLogCritical  KLogLevel = 2
	KLogError     KLogLevel = 3
	KLogWarning   KLogLevel = 4
	KLogNotice    KLogLevel = 5
	KLogInfo      KLogLevel = 6
	KLogDebug     KLogLevel = 7
)

These are the log levels used by printk as described in syslog(2).

type Logger

type Logger interface {
	Printf(format string, v ...interface{})
	Print(v ...interface{})
}

Logger is a log receptacle.

It puts your information somewhere for safekeeping.

var Log Logger = log.New(os.Stderr, "", log.LstdFlags)

Log is a Logger that prints to stderr, like the default log package.

var Null Logger = emptyLogger{}

Null is a logger that prints nothing.

Directories

Path Synopsis
Package ulogtest implement the Logger interface via a test's testing.TB.Logf.
Package ulogtest implement the Logger interface via a test's testing.TB.Logf.

Jump to

Keyboard shortcuts

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