Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var LdJSONFormatter = func() { logrus.SetFormatter(&PoliteJSONFormatter{}) }
LdJSONFormatter Option formats the event log as line-delimited JSON
var LevelDebug = func() { logrus.SetLevel(logrus.DebugLevel) }
LevelDebug Option sets the log level to debug
var LevelError = func() { logrus.SetLevel(logrus.ErrorLevel) }
LevelDebug Option sets the log level to error
var LevelInfo = func() { logrus.SetLevel(logrus.InfoLevel) }
LevelDebug Option sets the log level to info
var TextFormatter = func() { logrus.SetFormatter(&logrus.TextFormatter{}) }
TextFormatter Option formats the event log as human-readable plain-text
Functions ¶
Types ¶
type DoneCloser ¶
type EventLogger ¶
type EventLogger interface { prelog.StandardLogger // Prefix is like PrefixLogger.Prefix. We override it here // because the type changes (we return EventLogger). // It's what happens when you wrap interfaces. Prefix(fmt string, args ...interface{}) EventLogger // Event merges structured data from the provided inputs into a single // machine-readable log event. // // If the context contains metadata, a copy of this is used as the base // metadata accumulator. // // If one or more loggable objects are provided, these are deep-merged into base blob. // // Next, the event name is added to the blob under the key "event". If // the key "event" already exists, it will be over-written. // // Finally the timestamp and package name are added to the accumulator and // the metadata is logged. Event(ctx context.Context, event string, m ...Loggable) EventBegin(ctx context.Context, event string, m ...Loggable) DoneCloser }
EventLogger extends the StandardLogger interface to allow for log items containing structured metadata
Example ¶
{ log := EventLogger(nil) e := log.EventBegin(context.Background(), "dial") e.Done() } { log := EventLogger(nil) e := log.EventBegin(context.Background(), "dial") _ = e.Close() // implements io.Closer for convenience }
Output:
type LogRotatorConfig ¶
type Loggable ¶
type Loggable interface {
Loggable() map[string]interface{}
}
Loggable describes objects that can be marshalled into Metadata for logging
type LoggableMap ¶
type LoggableMap map[string]interface{}
func (LoggableMap) Loggable ¶
func (l LoggableMap) Loggable() map[string]interface{}
type Metadata ¶
type Metadata map[string]interface{}
Metadata is a convenience type for generic maps
func DeepMerge ¶
DeepMerge merges the second Metadata parameter into the first. Nested Metadata are merged recursively. Primitives are over-written.
func Metadatify ¶
Metadatify converts maps into Metadata
func (Metadata) JsonString ¶
type Option ¶
type Option func()
func OutputRotatingLogFile ¶
func OutputRotatingLogFile(config LogRotatorConfig) Option
type PoliteJSONFormatter ¶
type PoliteJSONFormatter struct{}
PoliteJSONFormatter marshals entries into JSON encoded slices (without overwriting user-provided keys). How polite of it!