logger

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2016 License: MPL-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LevelFilter

func LevelFilter() *logutils.LevelFilter

LevelFilter returns a LevelFilter that is configured with the log levels that we use.

func Setup

func Setup(config *Config, ui cli.Ui) (*logutils.LevelFilter, *GatedWriter, *LogWriter, io.Writer, bool)

Setup is used to perform setup of several logging objects:

  • A LevelFilter is used to perform filtering by log level.
  • A GatedWriter is used to buffer logs until startup UI operations are complete. After this is flushed then logs flow directly to output destinations.
  • A LogWriter provides a mean to temporarily hook logs, such as for running a command like "consul monitor".
  • An io.Writer is provided as the sink for all logs to flow to.

The provided ui object will get any log messages related to setting up logging itself, and will also be hooked up to the gated logger. The final bool parameter indicates if logging was set up successfully.

func ValidateLevelFilter

func ValidateLevelFilter(minLevel logutils.LogLevel, filter *logutils.LevelFilter) bool

ValidateLevelFilter verifies that the log levels within the filter are valid.

Types

type Config

type Config struct {
	// LogLevel is the minimum level to be logged.
	LogLevel string

	// EnableSyslog controls forwarding to syslog.
	EnableSyslog bool

	// SyslogFacility is the destination for syslog forwarding.
	SyslogFacility string
}

Config is used to set up logging.

type GatedWriter

type GatedWriter struct {
	Writer io.Writer
	// contains filtered or unexported fields
}

GatedWriter is an io.Writer implementation that buffers all of its data into an internal buffer until it is told to let data through.

func (*GatedWriter) Flush

func (w *GatedWriter) Flush()

Flush tells the GatedWriter to flush any buffered data and to stop buffering.

func (*GatedWriter) Write

func (w *GatedWriter) Write(p []byte) (n int, err error)

type LogHandler

type LogHandler interface {
	HandleLog(string)
}

LogHandler interface is used for clients that want to subscribe to logs, for example to stream them over an IPC mechanism

type LogWriter

type LogWriter struct {
	sync.Mutex
	// contains filtered or unexported fields
}

LogWriter implements io.Writer so it can be used as a log sink. It maintains a circular buffer of logs, and a set of handlers to which it can stream the logs to.

func NewLogWriter

func NewLogWriter(buf int) *LogWriter

NewLogWriter creates a LogWriter with the given buffer capacity

func (*LogWriter) DeregisterHandler

func (l *LogWriter) DeregisterHandler(lh LogHandler)

DeregisterHandler removes a LogHandler and prevents more invocations

func (*LogWriter) RegisterHandler

func (l *LogWriter) RegisterHandler(lh LogHandler)

RegisterHandler adds a log handler to receive logs, and sends the last buffered logs to the handler

func (*LogWriter) Write

func (l *LogWriter) Write(p []byte) (n int, err error)

Write is used to accumulate new logs

type SyslogWrapper

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

SyslogWrapper is used to cleanup log messages before writing them to a Syslogger. Implements the io.Writer interface.

func (*SyslogWrapper) Write

func (s *SyslogWrapper) Write(p []byte) (int, error)

Write is used to implement io.Writer

Jump to

Keyboard shortcuts

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