Documentation ¶
Overview ¶
Package log implements a library for logging.
This is separate from the standard logging package because logging may be a high-impact activity, and therefore we wanted to provide as much flexibility as possible in the underlying implementation.
Index ¶
- func CopyStandardLogTo(l Level) error
- func Debugf(format string, v ...interface{})
- func Infof(format string, v ...interface{})
- func IsLogging(level Level) bool
- func SetLevel(newLevel Level)
- func SetTarget(target Emitter)
- func Stacks(all bool) []byte
- func Traceback(format string, v ...interface{})
- func TracebackAll(format string, v ...interface{})
- func Warningf(format string, v ...interface{})
- type BasicLogger
- type Emitter
- type GoogleEmitter
- type JSONEmitter
- type K8sJSONEmitter
- type Level
- type Logger
- type MultiEmitter
- type TestEmitter
- type TestLogger
- type Writer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CopyStandardLogTo ¶
CopyStandardLogTo redirects the stdlib log package global output to the global logger for the specified level.
func SetTarget ¶
func SetTarget(target Emitter)
SetTarget sets the log target.
This is not thread safe and shouldn't be called concurrently with any logging calls.
func Traceback ¶
func Traceback(format string, v ...interface{})
Traceback logs the given message and dumps a stacktrace of the current goroutine.
This will be print a traceback, tb, as Warningf(format+":\n%s", v..., tb).
func TracebackAll ¶
func TracebackAll(format string, v ...interface{})
TracebackAll logs the given message and dumps a stacktrace of all goroutines.
This will be print a traceback, tb, as Warningf(format+":\n%s", v..., tb).
Types ¶
type BasicLogger ¶
BasicLogger is the default implementation of Logger.
func (*BasicLogger) Debugf ¶
func (l *BasicLogger) Debugf(format string, v ...interface{})
Debugf implements logger.Debugf.
func (*BasicLogger) Infof ¶
func (l *BasicLogger) Infof(format string, v ...interface{})
Infof implements logger.Infof.
func (*BasicLogger) IsLogging ¶
func (l *BasicLogger) IsLogging(level Level) bool
IsLogging implements logger.IsLogging.
func (*BasicLogger) SetLevel ¶
func (l *BasicLogger) SetLevel(level Level)
SetLevel sets the logging level.
func (*BasicLogger) Warningf ¶
func (l *BasicLogger) Warningf(format string, v ...interface{})
Warningf implements logger.Warningf.
type Emitter ¶
type Emitter interface { // Emit emits the given log statement. This allows for control over the // timestamp used for logging. Emit(level Level, timestamp time.Time, format string, v ...interface{}) }
Emitter is the final destination for logs.
type GoogleEmitter ¶
type GoogleEmitter struct { // Emitter is the underlying emitter. Emitter }
GoogleEmitter is a wrapper that emits logs in a format compatible with package github.com/golang/glog.
type K8sJSONEmitter ¶
type K8sJSONEmitter struct {
Writer
}
K8sJSONEmitter logs messages in json format that is compatible with Kubernetes fluent configuration.
type Level ¶
type Level uint32
Level is the log level.
const ( // Warning indicates that output should always be emitted. Warning Level = iota // Info indicates that output should normally be emitted. Info // Debug indicates that output should not normally be emitted. Debug )
The following levels are fixed, and can never be changed. Since some control RPCs allow for changing the level as an integer, it is only possible to add additional levels, and the existing one cannot be removed.
func (Level) MarshalJSON ¶
MarshalJSON implements json.Marshaler.MarashalJSON.
func (*Level) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.UnmarshalJSON. It can unmarshal from both string names and integers.
type Logger ¶
type Logger interface { // Debugf logs a debug statement. Debugf(format string, v ...interface{}) // Infof logs at an info level. Infof(format string, v ...interface{}) // Warningf logs at a warning level. Warningf(format string, v ...interface{}) // IsLogging returns true iff this level is being logged. This may be // used to short-circuit expensive operations for debugging calls. IsLogging(level Level) bool }
Logger is a high-level logging interface. It is in fact, not used within the log package. Rather it is provided for others to provide contextual loggers that may append some addition information to log statement. BasicLogger satisfies this interface, and may be passed around as a Logger.
type MultiEmitter ¶
type MultiEmitter []Emitter
MultiEmitter is an emitter that emits to multiple Emitters.
type TestEmitter ¶
type TestEmitter struct {
TestLogger
}
TestEmitter may be used for wrapping tests.
type TestLogger ¶
type TestLogger interface {
Logf(format string, v ...interface{})
}
TestLogger is implemented by testing.T and testing.B.