Documentation ¶
Overview ¶
Package metrics defines a basic structure foundation for handling logs without much hassle, allow more different entries to be created. Inspired by https://medium.com/@tjholowaychuk/apex-log-e8d9627f4a9a.
Index ¶
- Variables
- func Apply(en *Entry, mods ...EntryMod)
- type Collector
- type CommitFunction
- type ConditionalProcessors
- type DoFn
- type Entry
- type EntryEmitter
- type EntryMod
- func Error(err error) EntryMod
- func Errorf(message string, m ...interface{}) EntryMod
- func Info(message string, m ...interface{}) EntryMod
- func Message(message string, m ...interface{}) EntryMod
- func Partial(mods ...EntryMod) EntryMod
- func RedAlert(err error, message string, m ...interface{}) EntryMod
- func Tags(ts ...string) EntryMod
- func Type(t string) EntryMod
- func With(key string, value interface{}) EntryMod
- func WithField(filter interface{}) EntryMod
- func WithFields(f Field) EntryMod
- func WithID(id string) EntryMod
- func WithMessage(level Level, message string, m ...interface{}) EntryMod
- func WithTimelapse(message string, f Field) EntryMod
- func WithTrace(t Trace) EntryMod
- func YellowAlert(err error, message string, m ...interface{}) EntryMod
- type Field
- func (p Field) Get(key string) (value interface{}, found bool)
- func (p Field) GetBool(key string) (bool, bool)
- func (p Field) GetFloat32(key string) (float32, bool)
- func (p Field) GetFloat64(key string) (float64, bool)
- func (p Field) GetInt(key string) (int, bool)
- func (p Field) GetInt16(key string) (int16, bool)
- func (p Field) GetInt32(key string) (int32, bool)
- func (p Field) GetInt64(key string) (int64, bool)
- func (p Field) GetInt8(key string) (int8, bool)
- func (p Field) GetString(key string) (string, bool)
- type FilterFn
- type Level
- type MetricConsumer
- type Metrics
- type Pair
- func (p *Pair) Append(key string, val interface{}) *Pair
- func (p *Pair) Fields() Field
- func (p *Pair) Get(key string) (value interface{}, found bool)
- func (p *Pair) GetBool(key string) (bool, bool)
- func (p *Pair) GetFloat32(key string) (float32, bool)
- func (p *Pair) GetFloat64(key string) (float64, bool)
- func (p *Pair) GetInt(key string) (int, bool)
- func (p *Pair) GetInt16(key string) (int16, bool)
- func (p *Pair) GetInt32(key string) (int32, bool)
- func (p *Pair) GetInt64(key string) (int64, bool)
- func (p *Pair) GetInt8(key string) (int8, bool)
- func (p *Pair) GetString(key string) (string, bool)
- func (p *Pair) Root() *Pair
- type Processors
- type Timelapse
- type Trace
Constants ¶
This section is empty.
Variables ¶
var (
ErrBatchEmitterClosed = errors.New("batcher already closed")
)
errors.
var NilPair = (*Pair)(nil)
NilPair defines a nil starting pair.
Functions ¶
Types ¶
type Collector ¶
Collector defines an interface which exposes a single method to collect internal data which is then returned as an Entry.
func Collect ¶
func Collect(fn EntryEmitter) Collector
Collect returns a Collector which executes provided function when called by Metric to run.
type CommitFunction ¶
CommitFunction defines a function type which is used to process a batch of Entry.
type ConditionalProcessors ¶
type ConditionalProcessors interface { Processors Can(Entry) bool }
ConditionalProcessors defines a Processor which first validate it's ability to process a giving Entry.
func Case ¶
func Case(fn FilterFn, procs ...Processors) ConditionalProcessors
Case returns a Processor object with the provided Augmenters and Metrics implemement objects for receiving metric Entries, where entries are filtered out based on a provided function.
type Entry ¶
type Entry struct { ID string `json:"id"` Function string `json:"function"` File string `json:"file"` Type string `json:"type"` Line int `json:"line"` Level Level `json:"level"` Field Field `json:"fields"` Time time.Time `json:"time"` Message string `json:"message"` Filter interface{} `json:"filter"` Tags []string `json:"tags"` Trace Trace `json:"trace"` Timelapse []Timelapse `json:"timelapse"` }
Entry represent a giving record of data at a giving period of time.
type EntryEmitter ¶
EntryEmitter defines a type which returns a entry when runned.
type EntryMod ¶
type EntryMod func(*Entry)
EntryMod defines a function type which receives a pointer to an entry.
func Error ¶
Error returns a entry where the message is the provided error.Error() value and the error is added as a key-value within the Entry fields.
func Errorf ¶
Errorf returns a entry where the message is the provided error.Error() value produced from the message and its provided values and the error is added as a key-value within the Entry fields.
func Partial ¶
Partial returns a new EntryMod which will always apply provided EntryMod to all provided Entry.
func With ¶
With returns a Entry set to the LogLevel of the previous and adds the giving key-value pair to the entry.
func WithField ¶
func WithField(filter interface{}) EntryMod
WithField returns a Entry and set the Filter to the provided value.
func WithFields ¶
WithFields adds all field key-value pair into associated Entry returning the Entry.
func WithMessage ¶
WithMessage returns a new Entry with the provided Level and message used.
func WithTimelapse ¶
WithTimelapse returns a Timelapse with associated field and message.
func WithTrace ¶
WithTrace returns itself after setting the giving trace value has the method trace for the giving Entry.
func YellowAlert ¶
YellowAlert returns an Entry with the level set to YellowAlertLvl.
type Field ¶
type Field map[string]interface{}
Field represents a giving map of values associated with a giving field value.
func (Field) GetFloat32 ¶
GetFloat32 collects the string value of a key if it exists.
func (Field) GetFloat64 ¶
GetFloat64 collects the string value of a key if it exists.
type FilterFn ¶
FilterFn defines a function type which takes a giving Entry returning a bool to indicate filtering state.
type Level ¶
type Level int
Level defines a int type which represent the a giving level of entry for a giving entry.
const ( RedAlertLvl Level = iota // Immediately notify everyone by mail level, because this is bad YellowAlertLvl // Immediately notify everyone but we can wait to tomorrow ErrorLvl // Error occured with some code due to normal opperation or odd behaviour (not critical) InfoLvl // Information for view about code operation (replaces Debug, Notice, Trace). )
level constants
type MetricConsumer ¶
type MetricConsumer interface { Processors Run(<-chan struct{}) }
MetricConsumer exposes a interface which allows the consumption of Entries into a underline system, which can be started through it's run method.
func BatchConsumer ¶
func BatchConsumer(maxSize int, maxwait time.Duration, fn CommitFunction) MetricConsumer
BatchConsumer returns a new instance of a batchConsumer.
type Pair ¶
type Pair struct {
// contains filtered or unexported fields
}
Pair defines a struct for storing a linked pair of key and values.
func Append ¶
Append returns a new Pair with the giving key and with the provded Pair set as it's previous link.
func (*Pair) Append ¶
Append returns a new pair with the giving key and value and its previous set to this pair.
func (*Pair) GetFloat32 ¶
GetFloat32 collects the string value of a key if it exists.
func (*Pair) GetFloat64 ¶
GetFloat64 collects the string value of a key if it exists.
type Processors ¶
Processors implements a single method to process a Entry.
func DoWith ¶
func DoWith(do DoFn) Processors
DoWith returns a Metrics object where all entries are applied to the provided function.
func FilterLevel ¶
func FilterLevel(l Level, procs ...Processors) Processors
FilterLevel will return a metrics where all Entry will be filtered by their Entry.Level if the level giving is greater or equal to the provided, then it will be received by the metrics subscribers.
func Switch ¶
func Switch(conditions ...ConditionalProcessors) Processors
Switch returns a new instance of a SwitchMaster.
type Timelapse ¶
type Timelapse struct { Message string `json:"message"` Time time.Time `json:"time"` Field Field `json:"fields"` }
Timelapse defines a message attached with a giving time value.
type Trace ¶
type Trace struct { File string `json:"file"` Package string `json:"Package"` Function string `json:"function"` LineNumber int `json:"line_number"` Stack []byte `json:"stack"` Comments []string `json:"comments"` Time time.Time `json:"end_time"` }
Trace defines a structure which contains the stack, start and endtime on a given from a trace call to trace a given call with stack details and execution time.
func NewTrace ¶
NewTrace returns a Trace object which is used to track the execution and stack details of a given trace call.
func NewTraceWithCallDepth ¶
NewTraceWithCallDepth returns a Trace object which is used to track the execution and stack details of a given trace call.