log

package
v5.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package log provides debug logging

Index

Constants

This section is empty.

Variables

View Source
var (
	// Default buffer size if any.
	DefaultSize = 1024
	// DefaultLog logger.
	DefaultLog = NewLog()
	// 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

Format 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.

func NewLog

func NewLog(opts ...Option) Log

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.

Directories

Path Synopsis
Package memory provides an in memory log buffer
Package memory provides an in memory log buffer

Jump to

Keyboard shortcuts

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