log

package
v1.5.3-rc.4 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

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 JSONFormat 是 JSON 格式化函数

func TextFormat

func TextFormat(r Record) string

TextFormat returns text format TextFormat 返回文本格式

Types

type FormatFunc

type FormatFunc func(Record) string

FormatFunc is a function which formats the output FormatFunc 是格式化输出的函数

type Log

type Log interface {
	// Read reads log entries from the logger
	// Read 从日志记录器中读取日志条目
	Read(...ReadOption) ([]Record, error)
	// Write writes records to log
	// Write 将记录写入日志
	Write(Record) error
	// Stream log records
	// Stream 日志记录流
	Stream() (Stream, error)
}

Log is debug log interface for reading and writing logs Log 是用于读写日志的调试日志接口

type Option

type Option func(*Options)

Option used by the logger Option 用于日志记录器

func Format

func Format(f FormatFunc) Option

Format sets the output format 设置输出格式

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 是环形缓冲区的大小
	Size int
	// Format specifies the output format
	// Format 指定输出格式
	Format FormatFunc
}

Options are logger options Options 是日志记录器选项

type ReadOption

type ReadOption func(*ReadOptions)

ReadOption used for reading the logs ReadOption 用于读取日志

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 指定要返回的日志数量
	Count int
	// Stream requests continuous log stream
	// Stream 请求连续的日志流
	Stream bool
}

ReadOptions for querying the logs ReadOptions 用于查询日志

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 Record 是日志记录条目

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