canlog

package module
v0.0.0-...-f4a9feb Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2019 License: MIT Imports: 3 Imported by: 0

README

Canlog - canonical log collector

Canlog is a thread safe canonical log collector. Canonical logs are basically structured summaries of events / requests.

How to use

Upon receiving a request or event, grab a refrence with canlog.Ref(). This is a unique string that identifies the event / request and should be propagated through your callstack with context.

When you have information to add to canlog, simply set it with the ref using canlog.Push(ref, name, value).

At the exit point of your request you can generate a standard map[string]interface{} from a ref with canlog.Pop(ref). As the name suggests, this will also remove all references to data for ref from canlog.

At this point you are free to add any additional data or emit through your normal logger.

How it works

Canlog creates a buffered channel for each ref with a reader routine setting values in to a normal golang map. This mechanism serializes writes to the map thus being thread safe without locks.

When calling canlog.Pop the reader routine is instructed to stop. A sync.WaitGroup is used to coordinate the reader stopping with the canlog.Pop returning.

License

MIT. See LICENSE

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Pop

func Pop(ref Reference) (map[string]interface{}, error)

func Push

func Push(ref interface{}, key string, value interface{}) error

Types

type Reference

type Reference string

func Ref

func Ref() Reference

Jump to

Keyboard shortcuts

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