klog

package
v0.0.0-...-a5cc2cf Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 21, 2015 License: Apache-2.0 Imports: 11 Imported by: 2

Documentation

Index

Constants

View Source
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
)
View Source
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.

View Source
const DefaultDedupRate = 1 * time.Second

DefaultDedupRate is used when Dedup.Rate is left empty.

View Source
const DefaultPathREST = "/debug/klog"

DefaultPathREST is the default REST path prefix used if none is provided explicitly.

View Source
const DefaultRingSize = 1000

DefaultRingSize is used if Ring.Size is set to 0.

Variables

View Source
var DefaultFatalPrinter = PrinterFunc(LogPrinter)

DefaultPrinter is the default printer used by the kfatal and kpanic functions in klog.

View Source
var DefaultPrinter = PrinterFunc(LogPrinter)

DefaultPrinter is the default printer used by the kprint functions in klog.

View Source
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

func Keyf(format string, args ...interface{}) string

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.

func (*Chained) Chain

func (chained *Chained) Chain(next Printer)

Chain sets printer to be called by PrintNext.

func (*Chained) PrintNext

func (chained *Chained) PrintNext(line *Line)

PrintNext forwards the line to the next printer in the pipeline.

type Chainer

type Chainer interface {
	Printer
	Chain(next Printer)
}

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.

func NewDedup

func NewDedup() *Dedup

NewDedup creates a new Dedup printer.

func (*Dedup) Init

func (dedup *Dedup) Init()

Init initializes the object. Note that calling this is optional since the object is lazily initialized as needed.

func (*Dedup) Print

func (dedup *Dedup) Print(line *Line)

Print checks the line checking for duplicates. If the line was never seen before it is passed to the chained printer right away otherwise it is held back and counted.

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 NewFilter

func NewFilter(def int) *Filter

NewFilter creates a new Filter configured to either FilterIn or FilterOut.

func (*Filter) Add

func (filter *Filter) Add(values ...string) *Filter

Add adds the given pattern to be used as a full-key match.

func (*Filter) AddPrefix

func (filter *Filter) AddPrefix(prefixes ...string) *Filter

AddPrefix adds the given pattern to be used as a prefix match.

func (*Filter) AddSuffix

func (filter *Filter) AddSuffix(suffixes ...string) *Filter

AddSuffix adds the given pattern to be used as a suffix match.

func (*Filter) Get

func (filter *Filter) Get() map[string][]string

Get returns the list of active filters.

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

func (filter *Filter) Print(line *Line)

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) Remove

func (filter *Filter) Remove(values ...string) *Filter

Remove removes the given pattern to be used as a full-key match.

func (*Filter) RemovePrefix

func (filter *Filter) RemovePrefix(prefixes ...string) *Filter

RemovePrefix removes the given pattern to be used as a prefix match.

func (*Filter) RemoveSuffix

func (filter *Filter) RemoveSuffix(suffixes ...string) *Filter

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.

func (*Line) String

func (line *Line) String() string

String returns a string representation of the line.

type Logger

type Logger struct {
	Chained
	Fatal Printer
}

Logger is used to inject newly created lines into a printer pipeline.

func New

func New(next Printer, fatal Printer) *Logger

New creates a new Logger which outputs to the given printer.

func (*Logger) KFatal

func (logger *Logger) KFatal(key string, v ...interface{})

KFatal is similar to log.Fatal but accepts a key as it's first parameter.

func (*Logger) KFatalf

func (logger *Logger) KFatalf(key, format string, v ...interface{})

KFatalf is similar to log.Fatalf but accepts a key as it's first parameter.

func (*Logger) KPanic

func (logger *Logger) KPanic(key string, v ...interface{})

KPanic is similar to log.Panic but accepts a key as it's first parameter.

func (*Logger) KPanicf

func (logger *Logger) KPanicf(key, format string, v ...interface{})

KPanicf is similar to log.Panicf but accepts a key as it's first parameter.

func (*Logger) KPrint

func (logger *Logger) KPrint(key string, v ...interface{})

KPrint is similar to log.Print but accepts a key as it's first parameter.

func (*Logger) KPrintf

func (logger *Logger) KPrintf(key, format string, v ...interface{})

KPrintf is similar to log.Printf 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

func Chain(printer Chainer, next Printer) Printer

Chain chains the given printer to the given chained printer and returns the chained printer.

func Fork

func Fork(printers ...Printer) Printer

Fork duplicates all received lines to multiple printers.

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

func NewRing(size int) *Ring

NewRing creates a new Ring printer of the given size. If size is 0 then DefaultRingSize is used instead.

func (*Ring) GetAll

func (ring *Ring) GetAll() []*Line

GetAll returns all the lines in the ring sorted by their timestamp.

func (*Ring) GetKey

func (ring *Ring) GetKey(key string) []*Line

GetKey returns all the lines in the ring with the given key sorted by their timestamp.

func (*Ring) GetPrefix

func (ring *Ring) GetPrefix(prefix string) []*Line

GetPrefix returns all the lines in the ring with the given prefix sorted by their timestamp.

func (*Ring) GetSuffix

func (ring *Ring) GetSuffix(suffix string) []*Line

GetSuffix returns all the lines in the ring with the given suffix sorted by their timestamp.

func (*Ring) Init

func (ring *Ring) Init()

Init initializes the object. Calling this is optional since the object will lazily initialize itself when needed.

func (*Ring) Print

func (ring *Ring) Print(line *Line)

Print adds the given line to the ring overwritting any older line present.

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

func NewRingREST(path string, size int) *RingREST

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

func (ring *RingREST) RESTRoutes() rest.Routes

RESTRoutes returns the set of gorest routes used to manipulate the Ring printer.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL