logbuf

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: Apache-2.0 Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package logbuf 提供带序号的内存环形日志缓冲,供前端增量拉取。

Index

Constants

View Source
const (
	LevelDebug = "debug"
	LevelInfo  = "info"
	LevelWarn  = "warn"
	LevelError = "error"
)

日志级别

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer

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

Buffer 是固定容量的环形缓冲,写满后覆盖最旧的日志。

func New

func New(size int, echo *log.Logger) *Buffer

New 创建容量为 size 的缓冲。

func (*Buffer) Add

func (b *Buffer) Add(level, source, msg string)

Add 追加一条日志。

func (*Buffer) Clear

func (b *Buffer) Clear()

Clear 清空缓冲,序号继续递增,保证前端增量拉取不会错乱。

func (*Buffer) Logger

func (b *Buffer) Logger(source string) *Logger

Logger 返回带来源标签的写入器,例如每条转发规则一个。

func (*Buffer) Since

func (b *Buffer) Since(seq uint64) []Entry

Since 返回序号大于 seq 的全部日志(按时间顺序)。seq 为 0 时返回全部。

type Entry

type Entry struct {
	Seq     uint64    `json:"seq"`
	Time    time.Time `json:"time"`
	Level   string    `json:"level"`
	Source  string    `json:"source,omitempty"`
	Message string    `json:"message"`
}

Entry 是一条日志。Seq 单调递增,前端用它做增量拉取。

type Logger

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

Logger 是绑定了来源标签的便捷写入器。

func (*Logger) Debugf

func (l *Logger) Debugf(format string, args ...any)

Debugf 写入调试日志。

func (*Logger) Errorf

func (l *Logger) Errorf(format string, args ...any)

Errorf 写入错误日志。

func (*Logger) Infof

func (l *Logger) Infof(format string, args ...any)

Infof 写入普通日志。

func (*Logger) Warnf

func (l *Logger) Warnf(format string, args ...any)

Warnf 写入警告日志。

Jump to

Keyboard shortcuts

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