Documentation
¶
Overview ¶
Package logbuf 提供带序号的内存环形日志缓冲,供前端增量拉取。
开启落盘(Persist)后,日志同时以 JSON Lines 批量追加到文件,重启后从文件恢复最近的日志。
Index ¶
- Constants
- type Buffer
- type Entry
- type Logger
- func (l *Logger) Debugf(format string, args ...any)
- func (l *Logger) Errorf(format string, args ...any)
- func (l *Logger) Infof(format string, args ...any)
- func (l *Logger) Log(level, msg string)
- func (l *Logger) ServerErrorLog() *log.Logger
- func (l *Logger) Source() string
- func (l *Logger) Warnf(format string, args ...any)
Constants ¶
const ( LevelDebug = "debug" LevelInfo = "info" LevelWarn = "warn" LevelError = "error" )
日志级别
const (
// DefaultFileBytes 为单个日志文件的默认上限,超过后轮转为 <文件>.1,即每个来源最多占用两倍空间
DefaultFileBytes = 2 << 20
)
落盘参数
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer 是固定容量的环形缓冲,写满后覆盖最旧的日志。
func (*Buffer) ClosePersist ¶ added in v0.5.6
func (b *Buffer) ClosePersist()
ClosePersist 把未写盘的日志写入文件并停止落盘,之后日志只保留在内存。未开启时什么也不做。
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) ServerErrorLog ¶ added in v0.3.0
ServerErrorLog 返回可设置为 http.Server.ErrorLog 的标准日志器, 把 net/http 内部错误(如 TLS 握手失败)写入本模块日志,同时保留 docker logs 输出。