Documentation ¶
Index ¶
- Constants
- Variables
- func AuditLogsSinceBoot(ctx context.Context) ([]string, error)
- func BootTime() (time.Time, error)
- func CollectSyslog() (func(context.Context, string) error, error)
- func ExtractFileName(entry Entry) string
- func UpstartLogsSinceBoot(ctx context.Context) ([]string, error)
- type ChromeEntry
- type ChromeReader
- type Entry
- type EntryPred
- type LineReader
- type Option
- type ParseError
- type ProgramName
- type Reader
- type SeverityName
Constants ¶
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 ¶
var ErrNotFound = errors.New("no matching message found")
ErrNotFound is returned when no matching message is found by a Wait call.
Functions ¶
func AuditLogsSinceBoot ¶
AuditLogsSinceBoot returns all audit logs since last boot.
func CollectSyslog ¶
CollectSyslog collects shards of system log between timing of calling this function and each call to the returned function.
func ExtractFileName ¶
ExtractFileName extracts source file name from Entry. If there are multiple file names, it extracts the last one.
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) 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 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) 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 ¶
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 ¶
NewReader starts a new Reader that reports syslog messages written after it is started. Close must be called after use.
func (*Reader) Read ¶
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 ¶
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" )