Help us shape the future of Go! Take the 2026 Go Developer Survey

clog

package module
v0.0.0-...-037dba9 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2019 License: MIT Imports: 8 Imported by: 0

README

Go Report Card GoDoc FriendsOfGo

Canonical Log lines

This package is a Go log library for create a Canonical log lines.

Required Reading

In order to understand how this library works, one must first be familiar with the term Canonical Log Lines.

WIP

This project is under construction

Contributing

Contributions are more than welcome, if you are interested please fork this repo and send your Pull Request.

License

MIT License, see LICENSE

Documentation

Index

Constants

View Source
const (
	// IncrementalSpan if only add this tag when create the Span, then only count the transactions but not
	// calculate any duration
	IncrementalSpan = iota + 1

	// DurationSpan if only add this tag when create the Span, then only calculate the total duration of
	// the all transactions but not count them.
	DurationSpan
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Line

type Line struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Line represent a Canonical Log Lines in which is accumulated all the information about the process.

func (*Line) AddTag

func (l *Line) AddTag(t Tag)

AddTag add new tag to the line.

func (*Line) AddTags

func (l *Line) AddTags(tags ...Tag)

AddTags add multiples tags to the line at once.

func (*Line) MarkAsCritical

func (l *Line) MarkAsCritical() *Line

MarkAsCritical change the severity of the line to CRITICAL.

func (*Line) MarkAsError

func (l *Line) MarkAsError() *Line

MarkAsError change the severity of the line to ERROR.

func (*Line) MarkAsInfo

func (l *Line) MarkAsInfo() *Line

MarkAsInfo change the severity of the line to INFO.

func (*Line) OpenSpan

func (l *Line) OpenSpan(key string, flag uint8) *Span

OpenSpan return an existing span into the line otherwise creates a new one. You need to specify which is the purpose of the Span with the flags: IncrementalSpan or DurationSpan or both.

func (*Line) Send

func (l *Line) Send()

Send preparing and send the line throw to all reporters initialized on the logger.

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger is our Logger for Canonical Log Lines implementation. You should initialize it using the New method.

func New

func New(opts ...LoggerOption) *Logger

New returns a new Logger If any report has ben added the log reporter will be the default

func (*Logger) LineFromContext

func (l *Logger) LineFromContext(ctx context.Context) (*Line, context.Context)

LineFromContext returns a canonical line using the line found in context. If not found a line in context then new line is created. The line created is mark as severity Info for reporter.

func (*Logger) NewLine

func (l *Logger) NewLine() *Line

NewLine initialize a new line. The line created is mark as severity Info for reporter.

func (*Logger) NewLineOnContext

func (l *Logger) NewLineOnContext(ctx context.Context) (*Line, context.Context)

NewLineOnContext initialize new line and add this line to the context. The line created is mark as severity Info for reporter.

type LoggerOption

type LoggerOption func(*Logger)

LoggerOption allow to adjust behaviour of the Logger to be created with New() method.

func WithReporters

func WithReporters(reporters ...reporter.Reporter) LoggerOption

WithReporters allow to add multiples reporters to our logger

type Span

type Span struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Span represents an active, un-finished span in the Canonical Log Line system.

func (*Span) FinishTransaction

func (s *Span) FinishTransaction(t Transaction)

FinishTransaction calculate the duration of the all transaction period and add to the transactions span.

func (*Span) StartTransaction

func (s *Span) StartTransaction(name string) Transaction

StartTransaction initialize a new transaction, this save the timestamp when transaction start.

func (*Span) String

func (s *Span) String() string

String return a string with a representation of the transaction inside the span according to your type.

type Tag

type Tag struct {
	// contains filtered or unexported fields
}

Tag represent a key-value pair to a logger's context.

func Any

func Any(key string, val interface{}) Tag

Any constructs a tag with any value.

func Bool

func Bool(key string, val bool) Tag

Bool constructs a tag that carries a bool.

func Error

func Error(key string, val error) Tag

Error constructs a tag that carries an error.

func Float32

func Float32(key string, val float32) Tag

Float32 constructs a tag that carries a float32.

func Float64

func Float64(key string, val float64) Tag

Float64 constructs a tag that carries a float64.

func Int

func Int(key string, val int) Tag

Int constructs a tag that carries an int64.

func Int8

func Int8(key string, val int8) Tag

Int8 constructs a tag that carries an int8.

func Int16

func Int16(key string, val int16) Tag

Int16 constructs a tag that carries an int16.

func Int32

func Int32(key string, val int32) Tag

Int32 constructs a tag that carries an int32.

func Int64

func Int64(key string, val int64) Tag

Int64 constructs a tag that carries an int64.

func Skip

func Skip() Tag

Skip constructs a tag no-op for handle with invalid arguments when construct other tags.

func String

func String(key, val string) Tag

String constructs a tag that carries a string.

func Uint

func Uint(key string, val uint) Tag

Uint constructs a tag that carries an int64.

func Uint8

func Uint8(key string, val uint8) Tag

Uint8 constructs a tag that carries an int8.

func Uint16

func Uint16(key string, val uint16) Tag

Uint16 constructs a tag that carries an int16.

func Uint32

func Uint32(key string, val uint32) Tag

Uint32 constructs a tag that carries a int32.

func Uint64

func Uint64(key string, val uint64) Tag

Uint64 constructs a tag that carries an int64.

func (Tag) String

func (t Tag) String() string

String transform tag to `logFmt format (https://brandur.org/logfmt)

type TagType

type TagType uint8

TagType indicates which property of the Tag struct should be used

type Transaction

type Transaction struct {
	// contains filtered or unexported fields
}

Transaction represent a sequence of information exchange and related work.

Directories

Path Synopsis
log

Jump to

Keyboard shortcuts

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