pkg

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package pkg 提供了通用的工具组件

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer

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

Buffer 实现了一个线程安全的日志缓冲区 用于批量收集日志条目,当达到指定大小时触发发送

func NewBuffer

func NewBuffer(size int) *Buffer

NewBuffer 创建一个新的缓冲区实例 参数:

  • size: 触发发送的目标大小

返回:

  • *Buffer: 初始化好的缓冲区实例

func (*Buffer) Add

func (b *Buffer) Add(entry LogEntry) bool

Add 向缓冲区添加一条日志 该方法是线程安全的,可以被多个goroutine同时调用 参数:

  • entry: 要添加的日志条目

返回:

  • bool: 如果缓冲区达到目标大小返回true,表示应该触发发送操作

func (*Buffer) Flush

func (b *Buffer) Flush() []LogEntry

Flush 清空并返回缓冲区中的所有日志条目 该方法是线程安全的 返回:

  • []LogEntry: 缓冲区中的所有日志条目

type LogEntry

type LogEntry struct {
	// Timestamp 是日志生成时的Unix纳秒时间戳
	// 使用纳秒级时间戳可以保证日志的精确排序
	Timestamp int64

	// Message 存储实际的日志内容
	// 可以是任意字符串消息
	Message string

	// Level 日志级别
	Level zapcore.Level
}

LogEntry 表示一条日志记录 包含时间戳和日志消息两个基本要素

Jump to

Keyboard shortcuts

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