logutil

package
v3.0.0-rc.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2018 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EventString

func EventString(event *logutilpb.Event) string

EventString returns the line in one string

func EventToBuffer

func EventToBuffer(event *logutilpb.Event, buf *bytes.Buffer)

EventToBuffer formats an individual Event into a buffer, without the final '\n'

func Flush

func Flush()

Flush calls the functions registered through OnFlush() and waits for them.

Programs that use servenv.Run*() will invoke Flush() automatically at shutdown. Other programs should defer logutil.Flush() at the beginning of main().

Concurrent calls to Flush are serialized.

func LogEvent

func LogEvent(logger Logger, event *logutilpb.Event)

LogEvent sends an event to a Logger, using the level specified in the event. The event struct is converted to a string with EventString().

func NewLoggerWriter

func NewLoggerWriter(logger Logger) io.Writer

NewLoggerWriter returns an io.Writer on top of the logger

func OnFlush

func OnFlush(fn func())

OnFlush registers a function to be called when Flush() is invoked.

func ProtoToTime

func ProtoToTime(ts *logutilpb.Time) time.Time

ProtoToTime converts a logutilpb.Time to a time.Time. proto3 will eventually support timestamps, at which point we'll retire this.

A nil pointer is like the empty timestamp.

func PurgeLogs

func PurgeLogs()

PurgeLogs removes any log files that were started more than keepLogs ago and that aren't the current log.

func TimeToProto

func TimeToProto(t time.Time) *logutilpb.Time

TimeToProto converts the time.Time to a logutilpb.Time.

Types

type CallbackLogger

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

CallbackLogger is a logger that sends the logging event to a callback for consumption.

func NewCallbackLogger

func NewCallbackLogger(f func(*logutilpb.Event)) *CallbackLogger

NewCallbackLogger returns a new logger to the given callback. Note this and the other objects using this object should either all use pointer receivers, or non-pointer receivers. (that is ChannelLogger and MemoryLogger). That way they can share the 'depth' parameter freely. In this code now, they all use pointer receivers.

func (*CallbackLogger) ErrorDepth

func (cl *CallbackLogger) ErrorDepth(depth int, s string)

ErrorDepth is part of the Logger interface

func (*CallbackLogger) Errorf

func (cl *CallbackLogger) Errorf(format string, v ...interface{})

Errorf is part of the Logger interface.

func (*CallbackLogger) InfoDepth

func (cl *CallbackLogger) InfoDepth(depth int, s string)

InfoDepth is part of the Logger interface.

func (*CallbackLogger) Infof

func (cl *CallbackLogger) Infof(format string, v ...interface{})

Infof is part of the Logger interface.

func (*CallbackLogger) Printf

func (cl *CallbackLogger) Printf(format string, v ...interface{})

Printf is part of the Logger interface.

func (*CallbackLogger) WarningDepth

func (cl *CallbackLogger) WarningDepth(depth int, s string)

WarningDepth is part of the Logger interface

func (*CallbackLogger) Warningf

func (cl *CallbackLogger) Warningf(format string, v ...interface{})

Warningf is part of the Logger interface.

type ChannelLogger

type ChannelLogger struct {
	CallbackLogger
	C chan *logutilpb.Event
}

ChannelLogger is a Logger that sends the logging events through a channel for consumption.

func NewChannelLogger

func NewChannelLogger(size int) *ChannelLogger

NewChannelLogger returns a CallbackLogger which will write the data on a channel

type ConsoleLogger

type ConsoleLogger struct{}

ConsoleLogger is a Logger that uses glog directly to log, at the right level.

Note that methods on ConsoleLogger must use pointer receivers, because otherwise an autogenerated conversion method will be inserted in the call stack when ConsoleLogger is used via TeeLogger, making the log depth incorrect.

func NewConsoleLogger

func NewConsoleLogger() *ConsoleLogger

NewConsoleLogger returns a simple ConsoleLogger.

func (*ConsoleLogger) ErrorDepth

func (cl *ConsoleLogger) ErrorDepth(depth int, s string)

ErrorDepth is part of the Logger interface.

func (*ConsoleLogger) Errorf

func (cl *ConsoleLogger) Errorf(format string, v ...interface{})

Errorf is part of the Logger interface

func (*ConsoleLogger) InfoDepth

func (cl *ConsoleLogger) InfoDepth(depth int, s string)

InfoDepth is part of the Logger interface.

func (*ConsoleLogger) Infof

func (cl *ConsoleLogger) Infof(format string, v ...interface{})

Infof is part of the Logger interface

func (*ConsoleLogger) Printf

func (cl *ConsoleLogger) Printf(format string, v ...interface{})

Printf is part of the Logger interface

func (*ConsoleLogger) WarningDepth

func (cl *ConsoleLogger) WarningDepth(depth int, s string)

WarningDepth is part of the Logger interface.

func (*ConsoleLogger) Warningf

func (cl *ConsoleLogger) Warningf(format string, v ...interface{})

Warningf is part of the Logger interface

type EventStream

type EventStream interface {
	// Recv returns the next event in the logs.
	// If there are no more, it will return io.EOF.
	Recv() (*logutilpb.Event, error)
}

EventStream is an interface used by RPC clients when the streaming RPC returns a stream of log events.

type Logger

type Logger interface {
	// Infof logs at INFO level. A newline is appended if missing.
	Infof(format string, v ...interface{})
	// Warningf logs at WARNING level. A newline is appended if missing.
	Warningf(format string, v ...interface{})
	// Errorf logs at ERROR level. A newline is appended if missing.
	Errorf(format string, v ...interface{})

	// Printf will just display information on stdout when possible.
	// No newline is appended.
	Printf(format string, v ...interface{})

	// InfoDepth allows call frame depth to be adjusted when logging to INFO.
	InfoDepth(depth int, s string)
	// WarningDepth allows call frame depth to be adjusted when logging to WARNING.
	WarningDepth(depth int, s string)
	// ErrorDepth allows call frame depth to be adjusted when logging to ERROR.
	ErrorDepth(depth int, s string)
}

Logger defines the interface to use for our logging interface. All methods should be thread safe (i.e. multiple go routines can call these methods simultaneously).

type LoggerWriter

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

LoggerWriter is an adapter that implements the io.Writer interface.

func (LoggerWriter) Write

func (lw LoggerWriter) Write(p []byte) (n int, err error)

Write implements io.Writer

type MemoryLogger

type MemoryLogger struct {
	CallbackLogger

	Events []*logutilpb.Event
	// contains filtered or unexported fields
}

MemoryLogger keeps the logging events in memory. All protected by a mutex.

func NewMemoryLogger

func NewMemoryLogger() *MemoryLogger

NewMemoryLogger returns a new MemoryLogger

func (*MemoryLogger) Clear

func (ml *MemoryLogger) Clear()

Clear clears the logs.

func (*MemoryLogger) String

func (ml *MemoryLogger) String() string

String returns all the lines in one String, separated by '\n'

type TeeLogger

type TeeLogger struct {
	One, Two Logger
}

TeeLogger is a Logger that sends its logs to two underlying logger

func NewTeeLogger

func NewTeeLogger(one, two Logger) *TeeLogger

NewTeeLogger returns a logger that sends its logs to both loggers

func (*TeeLogger) ErrorDepth

func (tl *TeeLogger) ErrorDepth(depth int, s string)

ErrorDepth is part of the Logger interface

func (*TeeLogger) Errorf

func (tl *TeeLogger) Errorf(format string, v ...interface{})

Errorf is part of the Logger interface

func (*TeeLogger) InfoDepth

func (tl *TeeLogger) InfoDepth(depth int, s string)

InfoDepth is part of the Logger interface

func (*TeeLogger) Infof

func (tl *TeeLogger) Infof(format string, v ...interface{})

Infof is part of the Logger interface

func (*TeeLogger) Printf

func (tl *TeeLogger) Printf(format string, v ...interface{})

Printf is part of the Logger interface

func (*TeeLogger) WarningDepth

func (tl *TeeLogger) WarningDepth(depth int, s string)

WarningDepth is part of the Logger interface

func (*TeeLogger) Warningf

func (tl *TeeLogger) Warningf(format string, v ...interface{})

Warningf is part of the Logger interface

type ThrottledLogger

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

ThrottledLogger will allow logging of messages but won't spam the logs.

func NewThrottledLogger

func NewThrottledLogger(name string, maxInterval time.Duration) *ThrottledLogger

NewThrottledLogger will create a ThrottledLogger with the given name and throttling interval.

func (*ThrottledLogger) Errorf

func (tl *ThrottledLogger) Errorf(format string, v ...interface{})

Errorf logs an error if not throttled.

func (*ThrottledLogger) Infof

func (tl *ThrottledLogger) Infof(format string, v ...interface{})

Infof logs an info if not throttled.

func (*ThrottledLogger) Warningf

func (tl *ThrottledLogger) Warningf(format string, v ...interface{})

Warningf logs a warning if not throttled.

Jump to

Keyboard shortcuts

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