logbuf

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: Apache-2.0 Imports: 5 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) Resize added in v0.2.0

func (b *Buffer) Resize(size int)

Resize 修改缓冲容量,保留最新的日志。

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) Log added in v0.3.0

func (l *Logger) Log(level, msg string)

Log 以指定级别写入一条已格式化的日志,供托管外部进程的输出使用。

func (*Logger) ServerErrorLog added in v0.3.0

func (l *Logger) ServerErrorLog() *log.Logger

ServerErrorLog 返回可设置为 http.Server.ErrorLog 的标准日志器, 把 net/http 内部错误(如 TLS 握手失败)写入本模块日志,同时保留 docker logs 输出。

func (*Logger) Source added in v0.3.0

func (l *Logger) Source() string

Source 返回日志来源标签。

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