go-vitess.v1: gopkg.in/src-d/go-vitess.v1/vt/logutil Index | Files

package logutil

import "gopkg.in/src-d/go-vitess.v1/vt/logutil"

Index

Package Files

console_logger.go flush.go flush_glog.go level.go logger.go logutil.go proto3.go purge.go throttled.go

func EventString Uses

func EventString(event *logutilpb.Event) string

EventString returns the line in one string

func EventToBuffer Uses

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

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

func Flush Uses

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 Uses

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 Uses

func NewLoggerWriter(logger Logger) io.Writer

NewLoggerWriter returns an io.Writer on top of the logger

func OnFlush Uses

func OnFlush(fn func())

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

func ProtoToTime Uses

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 Uses

func PurgeLogs()

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

func TimeToProto Uses

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

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

type CallbackLogger Uses

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

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

func NewCallbackLogger Uses

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 Uses

func (cl *CallbackLogger) Error(err error)

Error is part of the Logger interface

func (*CallbackLogger) ErrorDepth Uses

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

ErrorDepth is part of the Logger interface

func (*CallbackLogger) Errorf Uses

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

Errorf is part of the Logger interface.

func (*CallbackLogger) Errorf2 Uses

func (cl *CallbackLogger) Errorf2(err error, format string, v ...interface{})

Errorf2 is part of the Logger interface

func (*CallbackLogger) InfoDepth Uses

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

InfoDepth is part of the Logger interface.

func (*CallbackLogger) Infof Uses

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

Infof is part of the Logger interface.

func (*CallbackLogger) Printf Uses

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

Printf is part of the Logger interface.

func (*CallbackLogger) WarningDepth Uses

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

WarningDepth is part of the Logger interface

func (*CallbackLogger) Warningf Uses

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

Warningf is part of the Logger interface.

type ChannelLogger Uses

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

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

func NewChannelLogger Uses

func NewChannelLogger(size int) *ChannelLogger

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

type ConsoleLogger Uses

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 Uses

func NewConsoleLogger() *ConsoleLogger

NewConsoleLogger returns a simple ConsoleLogger.

func (*ConsoleLogger) Error Uses

func (cl *ConsoleLogger) Error(err error)

Error is part of the Logger interface

func (*ConsoleLogger) ErrorDepth Uses

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

ErrorDepth is part of the Logger interface.

func (*ConsoleLogger) Errorf Uses

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

Errorf is part of the Logger interface

func (*ConsoleLogger) Errorf2 Uses

func (cl *ConsoleLogger) Errorf2(err error, format string, v ...interface{})

Errorf2 is part of the Logger interface

func (*ConsoleLogger) InfoDepth Uses

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

InfoDepth is part of the Logger interface.

func (*ConsoleLogger) Infof Uses

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

Infof is part of the Logger interface

func (*ConsoleLogger) Printf Uses

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

Printf is part of the Logger interface

func (*ConsoleLogger) WarningDepth Uses

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

WarningDepth is part of the Logger interface.

func (*ConsoleLogger) Warningf Uses

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

Warningf is part of the Logger interface

type EventStream Uses

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 Uses

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{})
    // Errorf2 logs an error with stack traces at ERROR level. A newline is appended if missing.
    Errorf2(e error, message string, v ...interface{})

    Error(e error)
    // 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 Uses

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

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

func (LoggerWriter) Write Uses

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

Write implements io.Writer

type MemoryLogger Uses

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 Uses

func NewMemoryLogger() *MemoryLogger

NewMemoryLogger returns a new MemoryLogger

func (*MemoryLogger) Clear Uses

func (ml *MemoryLogger) Clear()

Clear clears the logs.

func (*MemoryLogger) String Uses

func (ml *MemoryLogger) String() string

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

type TeeLogger Uses

type TeeLogger struct {
    One, Two Logger
}

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

func NewTeeLogger Uses

func NewTeeLogger(one, two Logger) *TeeLogger

NewTeeLogger returns a logger that sends its logs to both loggers

func (*TeeLogger) Error Uses

func (tl *TeeLogger) Error(err error)

Error is part of the Logger interface

func (*TeeLogger) ErrorDepth Uses

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

ErrorDepth is part of the Logger interface

func (*TeeLogger) Errorf Uses

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

Errorf is part of the Logger interface

func (*TeeLogger) Errorf2 Uses

func (tl *TeeLogger) Errorf2(err error, format string, v ...interface{})

Errorf2 is part of the Logger interface

func (*TeeLogger) InfoDepth Uses

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

InfoDepth is part of the Logger interface

func (*TeeLogger) Infof Uses

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

Infof is part of the Logger interface

func (*TeeLogger) Printf Uses

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

Printf is part of the Logger interface

func (*TeeLogger) WarningDepth Uses

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

WarningDepth is part of the Logger interface

func (*TeeLogger) Warningf Uses

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

Warningf is part of the Logger interface

type ThrottledLogger Uses

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

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

func NewThrottledLogger Uses

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

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

func (*ThrottledLogger) Errorf Uses

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

Errorf logs an error if not throttled.

func (*ThrottledLogger) Infof Uses

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

Infof logs an info if not throttled.

func (*ThrottledLogger) Warningf Uses

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

Warningf logs a warning if not throttled.

Package logutil imports 15 packages (graph) and is imported by 70 packages. Updated 2019-07-02. Refresh now. Tools for package owners.