logutil

package
v2.0.0-alpha3+incompat... Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2015 License: BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// the usual logging levels
	LOGGER_INFO = iota
	LOGGER_WARNING
	LOGGER_ERROR

	// for messages that may contains non-logging events
	LOGGER_CONSOLE
)

The logger levels are used to store individual logging events

Variables

This section is empty.

Functions

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 LoggerEventToProto

func LoggerEventToProto(e *LoggerEvent) *pb.Event

LoggerEventToProto converts a LoggerEvent to proto

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 *pb.Time) time.Time

ProtoToTime converts a pb.Time to a time.Time.

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) *pb.Time

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

Types

type ChannelLogger

type ChannelLogger chan LoggerEvent

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

func NewChannelLogger

func NewChannelLogger(size int) ChannelLogger

NewChannelLogger returns a ChannelLogger fo the given size

func (ChannelLogger) Errorf

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

Errorf is part of the Logger interface

func (ChannelLogger) Infof

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

Infof is part of the Logger interface

func (ChannelLogger) Printf

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

Errorf is part of the Logger interface

func (ChannelLogger) Warningf

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

Warningf is part of the Logger interface

type ConsoleLogger

type ConsoleLogger struct{}

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

func NewConsoleLogger

func NewConsoleLogger() ConsoleLogger

NewConsoleLogger returns a simple ConsoleLogger

func (ConsoleLogger) Errorf

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

Errorf 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) Warningf

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

Warningf is part of the Logger interface

type Logger

type Logger interface {
	// The three usual interfaces, format should not contain the trailing '\n'
	Infof(format string, v ...interface{})
	Warningf(format string, v ...interface{})
	Errorf(format string, v ...interface{})

	// Printf will just display information on stdout when possible,
	// and will not add any '\n'.
	Printf(format string, v ...interface{})
}

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 LoggerEvent

type LoggerEvent struct {
	Time  time.Time
	Level int
	File  string
	Line  int
	Value string
}

LoggerEvent is used to manage individual logging events. It is used by ChannelLogger and MemoryLogger.

func ProtoToLoggerEvent

func ProtoToLoggerEvent(e *pb.Event) *LoggerEvent

ProtoToLoggerEvent converts a proto into a LoggerEvent

func (*LoggerEvent) String

func (event *LoggerEvent) String() string

String returns the line in one string

func (*LoggerEvent) ToBuffer

func (event *LoggerEvent) ToBuffer(buf *bytes.Buffer)

ToBuffer formats an individual LoggerEvent into a buffer, without the final '\n'

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 {
	Events []LoggerEvent
	// 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) Errorf

func (ml *MemoryLogger) Errorf(format string, v ...interface{})

Errorf is part of the Logger interface

func (*MemoryLogger) Infof

func (ml *MemoryLogger) Infof(format string, v ...interface{})

Infof is part of the Logger interface

func (*MemoryLogger) Printf

func (ml *MemoryLogger) Printf(format string, v ...interface{})

Printf is part of the Logger interface

func (*MemoryLogger) String

func (ml *MemoryLogger) String() string

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

func (*MemoryLogger) Warningf

func (ml *MemoryLogger) Warningf(format string, v ...interface{})

Warningf is part of the Logger interface

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

func (*TeeLogger) Errorf

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

func (*TeeLogger) Infof

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

func (*TeeLogger) Printf

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

func (*TeeLogger) Warningf

func (tl *TeeLogger) Warningf(format string, v ...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