logger

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2018 License: MPL-2.0 Imports: 14 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

	//LogFilePath is the path to write the logs to the user specified file.
	LogFilePath string

	//LogRotateDuration is the user specified time to rotate logs
	LogRotateDuration time.Duration

	//LogRotateBytes is the user specified byte limit to rotate logs
	LogRotateBytes int
}

Config is used to set up logging.

type GRPCLogger added in v1.3.0

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

GRPCLogger wrapps a *log.Logger and implements the grpclog.LoggerV2 interface allowing gRPC servers to log to the standard Consul logger.

func NewGRPCLogger added in v1.3.0

func NewGRPCLogger(config *Config, logger *log.Logger) *GRPCLogger

NewGRPCLogger creates a grpclog.LoggerV2 that will output to the supplied logger with Severity/Verbosity level appropriate for the given config.

Note that grpclog has Info, Warning, Error, Fatal severity levels AND integer verbosity levels for additional info. Verbose logs in glog are always INFO severity so we map Info,V0 to INFO, Info,V1 to DEBUG, and Info,V>1 to TRACE.

func (*GRPCLogger) Error added in v1.3.0

func (g *GRPCLogger) Error(args ...interface{})

Error implements grpclog.LoggerV2

func (*GRPCLogger) Errorf added in v1.3.0

func (g *GRPCLogger) Errorf(format string, args ...interface{})

Errorf implements grpclog.LoggerV2

func (*GRPCLogger) Errorln added in v1.3.0

func (g *GRPCLogger) Errorln(args ...interface{})

Errorln implements grpclog.LoggerV2

func (*GRPCLogger) Fatal added in v1.3.0

func (g *GRPCLogger) Fatal(args ...interface{})

Fatal implements grpclog.LoggerV2

func (*GRPCLogger) Fatalf added in v1.3.0

func (g *GRPCLogger) Fatalf(format string, args ...interface{})

Fatalf implements grpclog.LoggerV2

func (*GRPCLogger) Fatalln added in v1.3.0

func (g *GRPCLogger) Fatalln(args ...interface{})

Fatalln implements grpclog.LoggerV2

func (*GRPCLogger) Info added in v1.3.0

func (g *GRPCLogger) Info(args ...interface{})

Info implements grpclog.LoggerV2

func (*GRPCLogger) Infof added in v1.3.0

func (g *GRPCLogger) Infof(format string, args ...interface{})

Infof implements grpclog.LoggerV2

func (*GRPCLogger) Infoln added in v1.3.0

func (g *GRPCLogger) Infoln(args ...interface{})

Infoln implements grpclog.LoggerV2

func (*GRPCLogger) V added in v1.3.0

func (g *GRPCLogger) V(l int) bool

V implements grpclog.LoggerV2

func (*GRPCLogger) Warning added in v1.3.0

func (g *GRPCLogger) Warning(args ...interface{})

Warning implements grpclog.LoggerV2

func (*GRPCLogger) Warningf added in v1.3.0

func (g *GRPCLogger) Warningf(format string, args ...interface{})

Warningf implements grpclog.LoggerV2

func (*GRPCLogger) Warningln added in v1.3.0

func (g *GRPCLogger) Warningln(args ...interface{})

Warningln implements grpclog.LoggerV2

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 LogFile added in v1.2.3

type LogFile struct {

	//LastCreated represents the creation time of the latest log
	LastCreated time.Time

	//FileInfo is the pointer to the current file being written to
	FileInfo *os.File

	//MaxBytes is the maximum number of desired bytes for a log file
	MaxBytes int

	//BytesWritten is the number of bytes written in the current log file
	BytesWritten int64
	// contains filtered or unexported fields
}

LogFile is used to setup a file based logger that also performs log rotation

func (*LogFile) Write added in v1.2.3

func (l *LogFile) Write(b []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