syslog

package
v0.0.0-...-9474aff Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2022 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MessageFile is the name of main system log.
	MessageFile = "/var/log/messages"

	// ChromeLogFile is a symlink to the current Chrome log.
	ChromeLogFile = "/var/log/chrome/chrome"

	// NetLogFile is the name of network log.
	NetLogFile = "/var/log/net.log"
)

Variables

View Source
var ErrNotFound = errors.New("no matching message found")

ErrNotFound is returned when no matching message is found by a Wait call.

Functions

func AuditLogsSinceBoot

func AuditLogsSinceBoot(ctx context.Context) ([]string, error)

AuditLogsSinceBoot returns all audit logs since last boot.

func BootTime

func BootTime() (time.Time, error)

BootTime returns last boot time.

func CollectSyslog

func CollectSyslog() (func(context.Context, string) error, error)

CollectSyslog collects shards of system log between timing of calling this function and each call to the returned function.

func ExtractFileName

func ExtractFileName(entry Entry) string

ExtractFileName extracts source file name from Entry. If there are multiple file names, it extracts the last one.

func UpstartLogsSinceBoot

func UpstartLogsSinceBoot(ctx context.Context) ([]string, error)

UpstartLogsSinceBoot returns all upstart logs since last boot.

Types

type ChromeEntry

type ChromeEntry struct {
	// Severity indicates the severity of the message, e.g. "ERROR".
	Severity string
	// PID is the process ID of the Chrome process that wrote the message.
	PID int
	// Content is the CONTENT part of the message. For multi-line messages, only
	// the first line is included.
	Content string
}

ChromeEntry represents a log message entry of a Chrome-format messages.

type ChromeReader

type ChromeReader struct {
	// contains filtered or unexported fields
}

ChromeReader allows tests to read Chrome-format syslog messages (such as /var/log/chrome/chrome). It only reports messages written after it is started. It also deals with Chrome restart causing /var/log/chrome/chrome to point to a new file.

func NewChromeReader

func NewChromeReader(ctx context.Context, path string) (r *ChromeReader, retErr error)

NewChromeReader starts a new ChromeReader that reports Chrome log messages written after it is started. Close must be called after use.

func (*ChromeReader) Close

func (r *ChromeReader) Close() error

Close closes the ChromeReader.

func (*ChromeReader) Read

func (r *ChromeReader) Read() (*ChromeEntry, error)

Read returns the next log message. If the next message is not available yet, io.EOF is returned.

type Entry

type Entry struct {
	// Timestamp is the time when the log message was emitted.
	Timestamp time.Time
	// Severity indicates the severity of the message, e.g. "ERR".
	Severity string
	// Tag is the TAG part of the message, e.g. "shill[1003]".
	Tag string
	// Program is the program name found in TAG, e.g. "shill".
	Program string
	// PID is the PID found in TAG. It is 0 if missing.
	PID int
	// Content is the CONTENT part of the message.
	Content string

	// Line is the raw syslog line. It always ends with a newline character.
	Line string
}

Entry represents a log message entry of syslog.

type EntryPred

type EntryPred func(e *Entry) bool

EntryPred is a predicate of Entry. It should return false if e should be dropped.

type LineReader

type LineReader struct {
	// contains filtered or unexported fields
}

LineReader is a common helper for Reader and ChromeReader. It handles getting each time and handles issues like log rotation and partially-written lines.

func NewLineReader

func NewLineReader(ctx context.Context, path string, fromStart bool, opts *testing.PollOptions) (r *LineReader, retErr error)

NewLineReader starts a new LineReader that reports log messages. If fromStart is false only reports log messages written after the reader is created. Close must be called after use. opts is used to customise polling for the file to exist e.g. in case the log is being rotated at the time we try to open it. Pass nil to get defaults.

func (*LineReader) Close

func (r *LineReader) Close() error

Close closes the LineReader.

func (*LineReader) ReadLine

func (r *LineReader) ReadLine() (string, error)

ReadLine returns the next log line. If the next message is not available yet, io.EOF is returned.

type Option

type Option func(*options)

Option allows tests to customize the behavior of Reader.

func Program

func Program(name ProgramName) Option

Program instructs Reader to report messages from a certain program only.

func Severities

func Severities(names ...SeverityName) Option

Severities instructs Reader to report messages from certain severities only.

func SourcePath

func SourcePath(p string) Option

SourcePath sets the file path to read syslog messages from. The default is /var/log/messages.

type ParseError

type ParseError struct {
	*errors.E

	// Line is a raw log line which failed to parse. It always ends with a
	// newline character.
	Line string
}

ParseError is returned when a log line failed to parse.

type ProgramName

type ProgramName string

ProgramName encloses names of the program in custom type.

const (
	// Chrome filter.
	Chrome ProgramName = "chrome"

	// CrashReporter filter.
	CrashReporter ProgramName = "crash_reporter"

	// Cryptohomed filter.
	Cryptohomed ProgramName = "cryptohomed"

	// Cupsd filter.
	Cupsd ProgramName = "cupsd"

	// CrashSender filter.
	CrashSender ProgramName = "crash_sender"
)

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

Reader allows tests to read syslog messages. It only reports messages written after it is started. It also deals with system log rotation.

func NewReader

func NewReader(ctx context.Context, opts ...Option) (r *Reader, retErr error)

NewReader starts a new Reader that reports syslog messages written after it is started. Close must be called after use.

func (*Reader) Close

func (r *Reader) Close() error

Close closes the Reader.

func (*Reader) Read

func (r *Reader) Read() (*Entry, error)

Read returns the next log message. If the next message is not available yet, io.EOF is returned. If the next line is read successfully but it failed to parse, *ParseError is returned.

func (*Reader) Wait

func (r *Reader) Wait(ctx context.Context, timeout time.Duration, f EntryPred) (*Entry, error)

Wait waits until it finds a log message matching f. If Wait returns successfully, the next call of Read or Wait will continue processing messages from the message immediately following the matched message. Otherwise the position of the Reader is somewhere between the starting position and the end of the file.

type SeverityName

type SeverityName string

SeverityName encloses names of the severity in custom type.

const (
	// Verbose1 filter.
	Verbose1 SeverityName = "VERBOSE1"

	// Verbose2 filter.
	// We should never be enabling VERBOSE3+ in system logs.
	Verbose2 SeverityName = "VERBOSE2"

	// Info filter.
	Info SeverityName = "INFO"

	// Debug filter.
	Debug SeverityName = "DEBUG"

	// Notice filter.
	Notice SeverityName = "NOTICE"

	// Warning filter.
	Warning SeverityName = "WARNING"

	// Err filter.
	Err SeverityName = "ERR"
)

Jump to

Keyboard shortcuts

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