log

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2021 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package log provides debug logging

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultSize Default buffer size if any
	DefaultSize = 256
	// DefaultFormat Default formatter
	DefaultFormat = TextFormat
)

Functions

func JSONFormat

func JSONFormat(r Record) string

JSONFormat is a json Format func

func TextFormat

func TextFormat(r Record) string

TextFormat returns text format

Types

type FormatFunc

type FormatFunc func(Record) string

FormatFunc is a function which formats the output

type Log

type Log interface {
	// Read reads log entries from the logger
	Read(...ReadOption) ([]Record, error)
	// Write writes records to log
	Write(Record) error
	// Stream log records
	Stream() (Stream, error)
}

Log is debug log interface for reading and writing logs

type Option

type Option func(*Options)

Option used by the logger

func Format

func Format(f FormatFunc) Option

func Name

func Name(n string) Option

Name of the log

func Size

func Size(s int) Option

Size sets the size of the ring buffer

type Options

type Options struct {
	// Name of the log
	Name string
	// Size is the size of ring buffer
	Size int
	// Format specifies the output format
	Format FormatFunc
}

Options are logger options

func DefaultOptions

func DefaultOptions() Options

DefaultOptions returns default options

type ReadOption

type ReadOption func(*ReadOptions)

ReadOption used for reading the logs

func Count

func Count(c int) ReadOption

Count sets the number of log records to return

func Since

func Since(s time.Time) ReadOption

Since sets the time since which to return the log records

type ReadOptions

type ReadOptions struct {
	// Since what time in past to return the logs
	Since time.Time
	// Count specifies number of logs to return
	Count int
	// Stream requests continuous log stream
	Stream bool
}

ReadOptions for querying the logs

type Record

type Record struct {
	// Timestamp of logged event
	Timestamp time.Time `json:"timestamp"`
	// Metadata to enrich log record
	Metadata map[string]string `json:"metadata"`
	// Value contains log entry
	Message interface{} `json:"message"`
}

Record is log record entry

type Stream

type Stream interface {
	Chan() <-chan Record
	Stop() error
}

Stream returns a log stream

Jump to

Keyboard shortcuts

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