Documentation ¶
Overview ¶
Package kvlog provides a key-value based logging system.
Example ¶
package main import ( "bitbucket.org/halimath/kvlog" ) func main() { kvlog.Debug(kvlog.KV("event", "test"), kvlog.KV("foo", "bar")) kvlog.Info(kvlog.KV("event", "test"), kvlog.KV("foo", "bar")) }
Output:
Index ¶
- Constants
- Variables
- func Debug(pairs ...KVPair)
- func Error(pairs ...KVPair)
- func Info(pairs ...KVPair)
- func Init(handler ...*Handler)
- func Middleware(l *Logger, h http.Handler) http.Handler
- func Warn(pairs ...KVPair)
- type Filter
- type FilterFunc
- type Formatter
- type FormatterFunc
- type Handler
- type KVPair
- type Level
- type Logger
- type Message
- type Output
Examples ¶
Constants ¶
const ( // KeyLevel defines the message key containing the message's level. KeyLevel = "level" // KeyTimestamp defines the message key containing the message's timestamp. KeyTimestamp = "ts" )
Variables ¶
var KVFormatter = FormatterFunc(formatMessage)
KVFormatter implements a Formatter that writes the default KV format.
Functions ¶
func Init ¶ added in v0.3.0
func Init(handler ...*Handler)
Init initializes the package global logger to a new logger using the given handler. The previous logger is closed if it had been set before.
func Middleware ¶ added in v0.3.0
Middleware returns a http.Handler that acts as an access log middleware.
Types ¶
type Filter ¶ added in v0.3.0
type Filter interface { // Filter filters the given message m and returns // either a message (which may be m) to be handled // or nil if the given message should be dropped. Filter(m Message) Message }
Filter defines the interface for types that filter messages.
type FilterFunc ¶ added in v0.3.0
FilterFunc is a wrapper type implementing Filter that wraps a plain function.
func (FilterFunc) Filter ¶ added in v0.3.0
func (f FilterFunc) Filter(m Message) Message
Filter just calls f to perform filtering.
type Formatter ¶ added in v0.3.0
type Formatter interface { // Formats the given message into a slice of bytes. Format(m Message, w io.Writer) error }
Formatter defines the interface implemented by all message formatters.
type FormatterFunc ¶ added in v0.3.0
FormatterFunc is a converter type that allows using a plain function as a Formatter.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler implements a threshold
func NewHandler ¶ added in v0.3.0
NewHandler creates a new Handler using the provided values.
type KVPair ¶
type KVPair struct { // Key stores the key of the pair Key string // Value stores the value Value interface{} }
KVPair implements a key-value pair
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger implements a logger component.
var L *Logger
L is the Logger instance used by package level functions. Use this logger as a convenience.
func (*Logger) Close ¶ added in v0.3.0
func (l *Logger) Close()
Close closes the handlers registered to this logger and waits for the goroutines to finish.
type Message ¶
type Message []KVPair
Message represents a single log message expressed as an ordered list of key value pairs
func NewMessage ¶
NewMessage creates a new message from the given log level and key-value pairs