Documentation ¶
Index ¶
- Constants
- func Flush()
- func LoggerEventToProto(e *LoggerEvent) *pb.Event
- func NewLoggerWriter(logger Logger) io.Writer
- func OnFlush(fn func())
- func ProtoToTime(ts *pb.Time) time.Time
- func PurgeLogs()
- func TimeToProto(t time.Time) *pb.Time
- type ChannelLogger
- type ConsoleLogger
- type Logger
- type LoggerEvent
- type LoggerWriter
- type MemoryLogger
- type TeeLogger
- type ThrottledLogger
Constants ¶
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 ¶
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 ¶
ProtoToTime converts a pb.Time to a time.Time.
A nil pointer is like the empty timestamp.
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 ¶
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.
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 ¶
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.