Documentation ¶
Index ¶
- Constants
- Variables
- func KFatal(key string, v ...interface{})
- func KFatalf(key, format string, v ...interface{})
- func KPanic(key string, v ...interface{})
- func KPanicf(key, format string, v ...interface{})
- func KPrint(key string, v ...interface{})
- func KPrintf(key, format string, v ...interface{})
- func Keyf(format string, args ...interface{}) string
- func LogPrinter(line *Line)
- func SetFatalPrinter(fatal Printer)
- func SetPrinter(next Printer)
- type Chained
- type Chainer
- type Dedup
- type Filter
- func (filter *Filter) Add(values ...string) *Filter
- func (filter *Filter) AddPrefix(prefixes ...string) *Filter
- func (filter *Filter) AddSuffix(suffixes ...string) *Filter
- func (filter *Filter) Get() map[string][]string
- func (filter *Filter) Init()
- func (filter *Filter) Print(line *Line)
- func (filter *Filter) Remove(values ...string) *Filter
- func (filter *Filter) RemovePrefix(prefixes ...string) *Filter
- func (filter *Filter) RemoveSuffix(suffixes ...string) *Filter
- type FilterREST
- type Line
- type Logger
- func (logger *Logger) KFatal(key string, v ...interface{})
- func (logger *Logger) KFatalf(key, format string, v ...interface{})
- func (logger *Logger) KPanic(key string, v ...interface{})
- func (logger *Logger) KPanicf(key, format string, v ...interface{})
- func (logger *Logger) KPrint(key string, v ...interface{})
- func (logger *Logger) KPrintf(key, format string, v ...interface{})
- type Printer
- type PrinterFunc
- type Ring
- type RingREST
Constants ¶
const ( // FilterOut indicates that by default all keys are allowed and that any keys // that hit on the filter will be discarded. FilterOut = 1 // FilterIn indicates that by default all keys are discarded and that only // keys that hit on the filter will be kept. FilterIn = 2 )
const DefaultBufferC = 8
DefaultBufferC is the default channel size for stages that defer printing to background go-routines. A well tuned parameter can reduce the overhead of going through a channel while introducing a slight delay in the output of the log line.
const DefaultDedupRate = 1 * time.Second
DefaultDedupRate is used when Dedup.Rate is left empty.
const DefaultPathREST = "/debug/klog"
DefaultPathREST is the default REST path prefix used if none is provided explicitly.
const DefaultRingSize = 1000
DefaultRingSize is used if Ring.Size is set to 0.
Variables ¶
var DefaultFatalPrinter = PrinterFunc(LogPrinter)
DefaultPrinter is the default printer used by the kfatal and kpanic functions in klog.
var DefaultPrinter = PrinterFunc(LogPrinter)
DefaultPrinter is the default printer used by the kprint functions in klog.
var NilPrinter = PrinterFunc(func(line *Line) {})
NilPrinter is a noop printer.
Functions ¶
func KFatal ¶
func KFatal(key string, v ...interface{})
KFatal is similar to fmt.Fatal but accepts a key as it's first parameter.
func KFatalf ¶
func KFatalf(key, format string, v ...interface{})
KFatalf is similar to fmt.Fatalf but accepts a key as it's first parameter.
func KPanic ¶
func KPanic(key string, v ...interface{})
KPanic is similar to fmt.Panic but accepts a key as it's first parameter.
func KPanicf ¶
func KPanicf(key, format string, v ...interface{})
KPanicf is similar to fmt.Panicf but accepts a key as it's first parameter.
func KPrint ¶
func KPrint(key string, v ...interface{})
KPrint is similar to fmt.Print but accepts a key as it's first parameter.
func KPrintf ¶
func KPrintf(key, format string, v ...interface{})
KPrintf is similar to fmt.Printf but accepts a key as it's first parameter.
func Keyf ¶
Keyf is a utility formatting functions for key and is a light wrapper around fmt.Sprintf.
func LogPrinter ¶
func LogPrinter(line *Line)
LogPrinter is forwards all lines to the golang standard log library.
func SetFatalPrinter ¶
func SetFatalPrinter(fatal Printer)
SetFatalPrinter changes the global printer used by the global KFatal and KPanic funcions. Since the program is about to go down after calling these functions, the printer should be short and sweet and not defer work to a background goroutine.
func SetPrinter ¶
func SetPrinter(next Printer)
SetPrinter changes the global printer used by the global KPrint and KPrintf function.
Types ¶
type Chained ¶
type Chained struct{ Next Printer }
Chained implements the Chain interface and contains the boilerplate required to setup a printer processing stage.
type Chainer ¶
Chainer represents a printer which forwards its output to another printer. Generally used to define a processing stage in a printer pipeline.
type Dedup ¶
type Dedup struct { Chained // Rate determines the interval at which duplicated lines are dumped. Rate time.Duration // contains filtered or unexported fields }
Dedup aggregates multiple consecutive identical lines into a single line with the number of time it was seen appended at the end. The first line encountered is always printed right away and only subsequent identical lines are held back prior to being printed. Held back line are printed at a set configurable rate.
type Filter ¶
type Filter struct { Chained // Type is either FilterOut or FilterIn. Type int // Keys is the initial set of keys that will be used for full-key matches. Keys []string // Prefixes is the initial set of patterns use for prefix matches. Prefixes []string // Suffixes is the initial set of patterns use for suffix matches. Suffixes []string // contains filtered or unexported fields }
Filter can filter a line stream on the key of each line and discard any undesired lines. Filters can either be a full, prefix or suffix string match.
func (*Filter) Init ¶
func (filter *Filter) Init()
Init initializes the filter. Calling this is optional since the object is lazily initialized as needed.
func (*Filter) Print ¶
Print forwards the line to the next printer if the filter is of type FilterIn and at least one of the patterns match the key or if the filter is of type FilterOut and none of the patterns match the key.
func (*Filter) RemovePrefix ¶
RemovePrefix removes the given pattern to be used as a prefix match.
func (*Filter) RemoveSuffix ¶
RemoveSuffix removes the given pattern to be used as a suffix match.
type FilterREST ¶
type FilterREST struct { *Filter // PathPrefix will be pre-pended to all the REST paths. Defaults to // DefaultPathREST. PathPrefix string }
FilterREST provides the REST interface for the Filter chained printer.
func NewFilterREST ¶
func NewFilterREST(path string, def int) *FilterREST
NewFilterREST creates a new REST enabled Filter chained printer at the specified path. The def parameter should be either FilterIn or FilterOut.
func (*FilterREST) RESTRoutes ¶
func (filter *FilterREST) RESTRoutes() rest.Routes
RESTRoutes returns the set of gorest routes used to manipulate the Filter chained printer.
type Line ¶
type Line struct { Timestamp time.Time `json:"ts"` Key string `json:"key"` Value string `json:"val"` }
Line represents a line to be printed by a printer pipeline.
type Logger ¶
Logger is used to inject newly created lines into a printer pipeline.
func (*Logger) KFatalf ¶
KFatalf is similar to log.Fatalf but accepts a key as it's first parameter.
func (*Logger) KPanicf ¶
KPanicf is similar to log.Panicf but accepts a key as it's first parameter.
type Printer ¶
type Printer interface {
Print(*Line)
}
Printer represents a stage in the printing pipeline.
func Chain ¶
Chain chains the given printer to the given chained printer and returns the chained printer.
func GetPrinter ¶
func GetPrinter() Printer
GetPrinter returns the global printer used by the global KPrint and KPrintf function.
type PrinterFunc ¶
type PrinterFunc func(*Line)
PrinterFunc implements the Printer interface for functions.
func (PrinterFunc) Print ¶
func (fn PrinterFunc) Print(line *Line)
Print passes the line to the function.
type Ring ¶
type Ring struct { // Size indicates the size of the ring used to log lines to. If 0 then // DefaultRingSize is used instead. Size int // contains filtered or unexported fields }
Ring adds all printed lines to a fixed size ring buffer which is written and read atomically. Lines in the ring are read-back all at once and can be filtered as needed.
func NewRing ¶
NewRing creates a new Ring printer of the given size. If size is 0 then DefaultRingSize is used instead.
func (*Ring) GetKey ¶
GetKey returns all the lines in the ring with the given key sorted by their timestamp.
func (*Ring) GetPrefix ¶
GetPrefix returns all the lines in the ring with the given prefix sorted by their timestamp.
func (*Ring) GetSuffix ¶
GetSuffix returns all the lines in the ring with the given suffix sorted by their timestamp.
type RingREST ¶
type RingREST struct { *Ring // PathPrefix will be preprended to all the REST paths. Defaults to // DefaultPathREST. PathPrefix string }
RingREST provides the REST interface for the Ring printer.
func NewRingREST ¶
NewRingREST creates a new REST enabled Ring printer at the specified path with the given size. If path is empty then DefaultPathREST will be used instead.
func (*RingREST) RESTRoutes ¶
RESTRoutes returns the set of gorest routes used to manipulate the Ring printer.