logging

package module
v0.0.0-...-dcb8702 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2018 License: Apache-2.0 Imports: 10 Imported by: 56

README

Logging

GoDoc Build Status Go Report Card codecov

This is a simple logging library for Go. It provides two outputs -- syslog and stderr. The stderr output can colour-code the output with ANSI escape codes, making it easy to vgrep the output on services during development.

Documentation

Index

Constants

View Source
const (
	// DebugLevel is the most detailed logging level. It will emit all log levels.
	DebugLevel uint = iota
	// InfoLevel is the log level that will log info, warning and errors
	InfoLevel
	// WarningLevel is the log level that will log warnings and errors
	WarningLevel
	// ErrorLevel is the log level that only logs errors
	ErrorLevel
)
View Source
const MemoryLoggerFlags = log.Lshortfile

MemoryLoggerFlags is the assumed layout for the log

Variables

This section is empty.

Functions

func Debug

func Debug(format string, v ...interface{})

Debug adds a debug-level log message to the log. If the log level is set higher than DebugLevel the message will be discarded.

func EnableMemoryLogger

func EnableMemoryLogger(logs []*MemoryLogger)

EnableMemoryLogger turns on logging to a memory logger.

func EnableNamedSyslog

func EnableNamedSyslog(name string)

EnableNamedSyslog enables sending logs to syslog with the given name.

func EnableStderr

func EnableStderr(plainText bool)

EnableStderr enables logging to stderr

func EnableSyslog

func EnableSyslog()

EnableSyslog enables syslog logging with the name "congress"

func Error

func Error(format string, v ...interface{})

Error adds an error-level log message to the log.

func Info

func Info(format string, v ...interface{})

Info adds an info-level log message to the log if the log level is set to InfoLevel or lower.

func ResetColors

func ResetColors()

ResetColors prints the ANSI color reset code

func SetLogLevel

func SetLogLevel(level uint)

SetLogLevel sets the logging level

func Warning

func Warning(format string, v ...interface{})

Warning adds a warning-level log message if the log level is set to WarningLevel or lower.

Types

type LogEntry

type LogEntry struct {
	Time     time.Time
	Location string
	Message  string
	Next     *LogEntry
	Level    uint
}

LogEntry is a linked list entry that holds log entries

func NewLogEntry

func NewLogEntry(input string, level uint) *LogEntry

NewLogEntry creates a new log entry

type MemoryLogger

type MemoryLogger struct {
	FirstEntry *LogEntry
	LastEntry  *LogEntry
	// contains filtered or unexported fields
}

MemoryLogger is a type that logs to memory. The logs are stored in a linked list.

func NewMemoryLogger

func NewMemoryLogger(maxEntries int, l uint) *MemoryLogger

NewMemoryLogger creates a new memory logger

func NewMemoryLoggers

func NewMemoryLoggers(maxEntries int) []*MemoryLogger

NewMemoryLoggers is a convenience function to create logs for all levels

func (*MemoryLogger) Entries

func (m *MemoryLogger) Entries() []LogEntry

Entries returns the entries

func (*MemoryLogger) Merge

func (m *MemoryLogger) Merge(other ...*MemoryLogger) []LogEntry

Merge merges this and a number of other logs

func (*MemoryLogger) NumEntries

func (m *MemoryLogger) NumEntries() int

NumEntries returns the number of entries in the log in total. This is increased for every time something is logged to the logger.

func (*MemoryLogger) Write

func (m *MemoryLogger) Write(p []byte) (n int, err error)

Write is a stub. This is the io.Writer implementation

type TerminalLogger

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

TerminalLogger is a logger that creates a console logging screen with logs that can be toggled runtime.

func NewTerminalLogger

func NewTerminalLogger(logs []*MemoryLogger) *TerminalLogger

NewTerminalLogger creates a new TerminalLogger instance using the specified MemoryLogger instances.

func (*TerminalLogger) Start

func (t *TerminalLogger) Start() error

Start launches the logging screen. If there's an error launching the screen it will be returned. The method doesn't return until the user presses the escape key.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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