logz

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2021 License: MIT Imports: 4 Imported by: 3

README

logz

This library provides in-process aggregated collector of messages and web page to report them. They are useful for last mile observability of logs.

logz is inspired by OpenCensus zPages.

Build Status Coverage Status GoDevDoc Code lines Comments

Features

  • High performance and low resource consumption.
  • Adapter for go.uber.org/zap.
  • HTTP handler to serve aggregated messages.

Screenshot

Example

zc := zap.NewDevelopmentConfig()
zz, lo := zzap.NewOption(logz.Config{
    MaxCardinality: 5,
    MaxSamples:     10,
})

l, err := zc.Build(zz)
if err != nil {
    panic(err)
}

l.Debug("starting example")
l.Sugar().Infow("sample info", "one", 1, "two", 2)
l.Error("unexpected end of the world")

l.Info("starting server at http://localhost:6060/")
err = http.ListenAndServe("0.0.0.0:6060", logzpage.Handler(lo...))
if err != nil {
    l.Fatal(err.Error())
}

Documentation

Overview

Package logz provides events observer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bucket

type Bucket struct {
	From  time.Time
	To    time.Time
	Count uint64
}

Bucket contains count of events in time interval.

type Config

type Config struct {
	// Name can be used to identify observer instance in a group, for example a group of log levels.
	Name string

	// MaxCardinality limits number of distinct message families being tracked.
	// All messages that exceed cardinality are grouped together as "other".
	// Default 100.
	MaxCardinality uint32

	// MaxSamples limits a number of latest samples kept for a message family.
	// Default 10.
	MaxSamples uint32

	// SamplingInterval is the minimum amount of time needed to pass from a last sample collection in particular message family.
	// Messages that are observed too quickly after last sampling are counted, but not sampled.
	// Default 1ms.
	SamplingInterval time.Duration

	// DistResolution is the maximum number of time interval buckets to track distribution in time.
	// Default 100.
	DistResolution int

	// DistRetentionPeriod is maximum age of bucket. Use -1 for unlimited.
	// Default one week (168 hours).
	DistRetentionPeriod time.Duration
}

Config defines observer configuration.

type Entry

type Entry struct {
	Message string
	Count   uint64
	Samples []interface{}
	First   time.Time
	Last    time.Time

	MaxBucketCount int
	Buckets        []Bucket
}

Entry contains aggregated information about message.

type Observer

type Observer struct {
	Config
	// contains filtered or unexported fields
}

Observer keeps track of messages.

func (*Observer) Find

func (l *Observer) Find(msg string) Entry

Find lookups entry by message.

func (*Observer) GetEntries

func (l *Observer) GetEntries() []Entry

GetEntries returns a list of observed event entries without data samples.

func (*Observer) GetEntriesWithSamples added in v0.1.3

func (l *Observer) GetEntriesWithSamples() []Entry

GetEntriesWithSamples returns a list of observed event entries with data samples.

func (*Observer) ObserveMessage

func (l *Observer) ObserveMessage(msg string, data interface{})

ObserveMessage updates aggregated information about message.

func (*Observer) Other

func (l *Observer) Other(withSamples bool) Entry

Other returns entry for other events.

Directories

Path Synopsis
Package logzpage provides http handler to expose observed log samples.
Package logzpage provides http handler to expose observed log samples.
Package zzap provides zpage observer for "go.uber.org/zap" logger.
Package zzap provides zpage observer for "go.uber.org/zap" logger.

Jump to

Keyboard shortcuts

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