Documentation ¶
Index ¶
- func EventString(event *logutilpb.Event) string
- func EventToBuffer(event *logutilpb.Event, buf *bytes.Buffer)
- func Flush()
- func LogEvent(logger Logger, event *logutilpb.Event)
- func NewLoggerWriter(logger Logger) io.Writer
- func OnFlush(fn func())
- func ProtoToTime(ts *vttimepb.Time) time.Time
- func PurgeLogs()
- func RegisterFlags(fs *pflag.FlagSet)
- func TimeToProto(t time.Time) *vttimepb.Time
- type CallbackLogger
- func (cl *CallbackLogger) Error(err error)
- func (cl *CallbackLogger) ErrorDepth(depth int, s string)
- func (cl *CallbackLogger) Errorf(format string, v ...any)
- func (cl *CallbackLogger) Errorf2(err error, format string, v ...any)
- func (cl *CallbackLogger) InfoDepth(depth int, s string)
- func (cl *CallbackLogger) Infof(format string, v ...any)
- func (cl *CallbackLogger) Printf(format string, v ...any)
- func (cl *CallbackLogger) WarningDepth(depth int, s string)
- func (cl *CallbackLogger) Warningf(format string, v ...any)
- type ChannelLogger
- type ConsoleLogger
- func (cl *ConsoleLogger) Error(err error)
- func (cl *ConsoleLogger) ErrorDepth(depth int, s string)
- func (cl *ConsoleLogger) Errorf(format string, v ...any)
- func (cl *ConsoleLogger) Errorf2(err error, format string, v ...any)
- func (cl *ConsoleLogger) InfoDepth(depth int, s string)
- func (cl *ConsoleLogger) Infof(format string, v ...any)
- func (cl *ConsoleLogger) Printf(format string, v ...any)
- func (cl *ConsoleLogger) WarningDepth(depth int, s string)
- func (cl *ConsoleLogger) Warningf(format string, v ...any)
- type EventStream
- type Logger
- type LoggerWriter
- type MemoryLogger
- type TeeLogger
- func (tl *TeeLogger) Error(err error)
- func (tl *TeeLogger) ErrorDepth(depth int, s string)
- func (tl *TeeLogger) Errorf(format string, v ...any)
- func (tl *TeeLogger) Errorf2(err error, format string, v ...any)
- func (tl *TeeLogger) InfoDepth(depth int, s string)
- func (tl *TeeLogger) Infof(format string, v ...any)
- func (tl *TeeLogger) Printf(format string, v ...any)
- func (tl *TeeLogger) WarningDepth(depth int, s string)
- func (tl *TeeLogger) Warningf(format string, v ...any)
- type ThrottledLogger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EventString ¶
EventString returns the line in one string
func EventToBuffer ¶
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 ¶
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 ¶
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 vttimepb.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 RegisterFlags ¶ added in v0.15.0
RegisterFlags installs logutil flags on the given FlagSet.
`go/cmd/*` entrypoints should either use servenv.ParseFlags(WithArgs)? which calls this function, or call this function directly before parsing command-line arguments.
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) Error ¶
func (cl *CallbackLogger) Error(err error)
Error is part of the Logger interface
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 ...any)
Errorf is part of the Logger interface.
func (*CallbackLogger) Errorf2 ¶
func (cl *CallbackLogger) Errorf2(err error, format string, v ...any)
Errorf2 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 ...any)
Infof is part of the Logger interface.
func (*CallbackLogger) Printf ¶
func (cl *CallbackLogger) Printf(format string, v ...any)
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 ...any)
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) Error ¶
func (cl *ConsoleLogger) Error(err error)
Error is part of the Logger interface
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 ...any)
Errorf is part of the Logger interface
func (*ConsoleLogger) Errorf2 ¶
func (cl *ConsoleLogger) Errorf2(err error, format string, v ...any)
Errorf2 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 ...any)
Infof is part of the Logger interface
func (*ConsoleLogger) Printf ¶
func (cl *ConsoleLogger) Printf(format string, v ...any)
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 ...any)
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 ...any) // Warningf logs at WARNING level. A newline is appended if missing. Warningf(format string, v ...any) // Errorf logs at ERROR level. A newline is appended if missing. Errorf(format string, v ...any) // Errorf2 logs an error with stack traces at ERROR level. A newline is appended if missing. Errorf2(e error, message string, v ...any) Error(e error) // Printf will just display information on stdout when possible. // No newline is appended. Printf(format string, v ...any) // 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.
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) 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 ¶
NewTeeLogger returns a logger that sends its logs to both loggers
func (*TeeLogger) ErrorDepth ¶
ErrorDepth is part of the Logger interface
func (*TeeLogger) WarningDepth ¶
WarningDepth 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 ...any)
Errorf logs an error if not throttled.
func (*ThrottledLogger) Infof ¶
func (tl *ThrottledLogger) Infof(format string, v ...any)
Infof logs an info if not throttled.
func (*ThrottledLogger) Warningf ¶
func (tl *ThrottledLogger) Warningf(format string, v ...any)
Warningf logs a warning if not throttled.