Documentation ¶
Index ¶
- Constants
- type JSONSink
- type KV
- type Level
- type Logger
- func (l *Logger) Debug(args ...interface{}) error
- func (l *Logger) Debugf(format string, args ...interface{}) error
- func (l *Logger) Error(args ...interface{}) error
- func (l *Logger) Errorf(format string, args ...interface{}) error
- func (l *Logger) ForComponent(component string) *Logger
- func (l *Logger) ForRegion(region string) *Logger
- func (l *Logger) ForTask(task string) *Logger
- func (l *Logger) Info(args ...interface{}) error
- func (l *Logger) Infof(format string, args ...interface{}) error
- func (l *Logger) SetLevel(lv Level)
- func (l *Logger) WithKV(kv KV) *Logger
- type Sink
- type TB
- type Tee
- type TestLogSink
- type TextSink
Constants ¶
const ( LevelKey = "_level" TimestampKey = "_ts" ComponentKey = "_component" TaskKey = "_task" RegionKey = "_region" MsgKey = "_msg" )
Reserved built-in keys
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type JSONSink ¶
JSONSink emits JSON objects to an output stream. JSONSink values must not be copied.
func (*JSONSink) Drain ¶
Drain encodes the specified key-value pairs to JSON, then writes them out to the underyling io.Writer.
When using JSONSink, callers must ensure that all values in the KV map can be JSON-encoded, otherwise the resulting object may be malformed, or encoding might fail.
Drain makes a single Write call to the underlying io.Writer.
type KV ¶
type KV map[string]interface{}
KV is a collection of key-value pairs.
func (KV) SortedKeys ¶
SortedKeys returns all keys in the map, sorted in the order prescribed by this package. Built-in keys go first, in the order "_level", "_ts", "_component", "_task", "_region", "_msg", followed by user-defined keys, sorted lexicographically.
type Level ¶
type Level uint32
Level represents a log level.
func (Level) MarshalJSON ¶
MarshalJSON marshals lv as a JSON string.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is a structured, leveled logger.
func New ¶
New creates a new Logger which forwards logs at or below the specified level to the specified Sink.
func (*Logger) ForComponent ¶
ForComponent returns a Logger for the specified component.
func (*Logger) ForRegion ¶
ForRegion returns a Logger for the specified region. ForRegion is intended to be used in conjunction with a *runtime/trace.Region. By convention, the region names should match.
func (*Logger) ForTask ¶
ForTask returns a Logger for the specified task. ForTask is intended to be used in conjunction with a *runtime/trace.Task. By convention, the task names should match.
type Sink ¶
A Sink encodes key-value pairs and produces a log message. Implementations of Sink must be safe for concurrent use.
Implementations of Sink which produce output where the order of key-value pairs is significant should use KV.SortedKeys to determine the order prescribed by this package.
Implementations of Sink must not modify KV maps.
type TB ¶
type TB interface {
Log(args ...interface{})
}
TB is the portion of testing.TB TestLogSink uses.
type TestLogSink ¶
type TestLogSink struct { TB TB // contains filtered or unexported fields }
TestLogSink emits textual log messages to a testing.TB. TestLogSink values must not be copied.
func (*TestLogSink) Drain ¶
func (tls *TestLogSink) Drain(kv KV) error
Drain encodes the specified key-value pairs to text, then writes them to the associated testing.TB's log. The encoding is identical to that of TextSink, except for the trailing newline, which is omitted.
type TextSink ¶
TextSink emits textual log messages to an output stream. TextSink values must not be copied.
func (*TextSink) Drain ¶
Drain encodes the specified key-value pairs to text, then writes them to the underlying io.Writer, followed by a newline.
Values are formatted using fmt.Sprint. If the textual representation of values contains whitespace or unprintable characters (in accordance with unicode.IsSpace and unicode.IsPrint), the values are quoted.
Drain makes a single Write call to the underlying io.Writer.