Documentation ¶
Index ¶
- Constants
- type Event
- type JSONSink
- type KV
- type KVer
- type Level
- type Logger
- func (l *Logger) Debug(kvers ...KVer) error
- func (l *Logger) Error(err error, kvers ...KVer) 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(kvers ...KVer) error
- func (l *Logger) SetLevel(lv Level)
- func (l *Logger) WithKV(kver ...KVer) *Logger
- type Op
- type Sink
- type Tee
- type TextSink
Constants ¶
const ( LevelKey = "level" TimestampKey = "ts" ComponentKey = "component" TaskKey = "task" RegionKey = "region" ErrorKey = "error" )
Reserved built-in keys
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Event ¶ added in v0.6.0
type Event string
Event represents an event. It occupies the "event" key in a KV.
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", "error", followed by user-defined keys, sorted lexicographically.
type KVer ¶ added in v0.3.0
type KVer interface {
KV() KV
}
KVer is any type which can represent itself as a key-value pair.
type Level ¶
type Level uint32
Level represents a log level.
func (Level) MarshalJSON ¶
MarshalJSON marshals lv as a JSON string.
func (*Level) Set ¶ added in v0.4.0
Set implements the flag.Value.Set method.
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) Debug ¶
Debug emits a log message at the Debug level.
func (*Logger) Error ¶
Error emits a log message at the Error level.
func (*Logger) ForComponent ¶
ForComponent returns a Logger for the specified component. If a component key exists in one of the parent loggers, the specified component name is appended to it in the returned logger, per acln.ro/hiername.
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. If a region key exists in one of the parent loggers, the specified region name is appended to it in the returned logger, per acln.ro/hiername.
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. If a task key exists in one of the parent loggers, the specified task name is appended to it in the returned logger, per acln.ro/hiername.
func (*Logger) Info ¶
Info emits a log message at the Info level.
type Op ¶ added in v0.5.0
type Op string
Op represents an operation. It occupies the "op" key in a KV.
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 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.