Documentation
¶
Index ¶
- Constants
- func GenerateID() string
- type Config
- type Controller
- type ControllerConfig
- type DatabaseStorage
- func (ds *DatabaseStorage) Cleanup(before time.Time) error
- func (ds *DatabaseStorage) Close() error
- func (ds *DatabaseStorage) CreateIndexes() error
- func (ds *DatabaseStorage) FindAll(page, pageSize int, filters map[string]interface{}) ([]*LogEntry, int, error)
- func (ds *DatabaseStorage) FindByID(id string) (*LogEntry, error)
- func (ds *DatabaseStorage) GetMethods() (map[string]int, error)
- func (ds *DatabaseStorage) GetStats() (map[string]interface{}, error)
- func (ds *DatabaseStorage) GetStatusCodes() (map[int]int, error)
- func (ds *DatabaseStorage) Save(entry *LogEntry) error
- func (ds *DatabaseStorage) Search(keyword string, page, pageSize int) ([]*LogEntry, int, error)
- type Debugger
- func New(config *Config) (*Debugger, error)
- func NewProductionDebugger(storagePath string) (*Debugger, error)
- func NewSimpleDebugger() (*Debugger, error)
- func NewWithCustomStorage(customStorage Storage) (*Debugger, error)
- func NewWithFileStorage(storagePath string, maxRecords int) (*Debugger, error)
- func NewWithMemoryStorage(maxRecords int) (*Debugger, error)
- func (d *Debugger) EndProcess(processID, status string) error
- func (d *Debugger) GetConfig() *Config
- func (d *Debugger) GetController() *Controller
- func (d *Debugger) GetLogger() LoggerInterface
- func (d *Debugger) GetLoggerWithFields(fields map[string]interface{}) LoggerInterface
- func (d *Debugger) GetMainLogger() LoggerInterface
- func (d *Debugger) GetMainLoggerWithFields(fields map[string]interface{}) LoggerInterface
- func (d *Debugger) GetProcessLogger(processID string) (ProcessLoggerInterface, error)
- func (d *Debugger) GetProcessRecords(page, pageSize int, filters map[string]interface{}) ([]*LogEntry, int, error)
- func (d *Debugger) GetStorage() Storage
- func (d *Debugger) Middleware() gin.HandlerFunc
- func (d *Debugger) RegisterRoutes(router *gin.Engine)
- func (d *Debugger) SetSessionData(c *gin.Context, data map[string]interface{})
- func (d *Debugger) StartProcess(processName, processType string) ProcessLoggerInterface
- func (d *Debugger) WithController(router *gin.Engine, config *ControllerConfig) *Debugger
- type DefaultLogger
- func (l *DefaultLogger) ClearLogs()
- func (l *DefaultLogger) Error(msg any, fields ...map[string]interface{})
- func (l *DefaultLogger) GetLevel() LogLevel
- func (l *DefaultLogger) GetLogs() []LoggerLog
- func (l *DefaultLogger) Info(msg any, fields ...map[string]interface{})
- func (l *DefaultLogger) Warn(msg any, fields ...map[string]interface{})
- func (l *DefaultLogger) WithFields(fields map[string]interface{}) LoggerInterface
- type DetailView
- type DetailViewer
- type FileStorage
- func (fs *FileStorage) Cleanup(before time.Time) error
- func (fs *FileStorage) Close() error
- func (fs *FileStorage) ExportAll(outputPath string) error
- func (fs *FileStorage) FindAll(page, pageSize int, filters map[string]interface{}) ([]*LogEntry, int, error)
- func (fs *FileStorage) FindByID(id string) (*LogEntry, error)
- func (fs *FileStorage) GetMethods() (map[string]int, error)
- func (fs *FileStorage) GetStats() (map[string]interface{}, error)
- func (fs *FileStorage) GetStatusCodes() (map[int]int, error)
- func (fs *FileStorage) ImportFromFile(filePath string) error
- func (fs *FileStorage) Save(entry *LogEntry) error
- func (fs *FileStorage) Search(keyword string, page, pageSize int) ([]*LogEntry, int, error)
- type LogEntry
- type LogEntryModel
- type LogLevel
- type LoggerInterface
- type LoggerLog
- type MainLogger
- func (l *MainLogger) Error(msg any, fields ...map[string]interface{})
- func (l *MainLogger) GetLevel() LogLevel
- func (l *MainLogger) Info(msg any, fields ...map[string]interface{})
- func (l *MainLogger) Warn(msg any, fields ...map[string]interface{})
- func (l *MainLogger) WithFields(fields map[string]interface{}) LoggerInterface
- type MemoryStorage
- func (ms *MemoryStorage) Cleanup(before time.Time) error
- func (ms *MemoryStorage) Clear() error
- func (ms *MemoryStorage) Close() error
- func (ms *MemoryStorage) ExportAll() ([]*LogEntry, error)
- func (ms *MemoryStorage) FindAll(page, pageSize int, filters map[string]interface{}) ([]*LogEntry, int, error)
- func (ms *MemoryStorage) FindByID(id string) (*LogEntry, error)
- func (ms *MemoryStorage) GetByTimeRange(startTime, endTime time.Time) ([]*LogEntry, error)
- func (ms *MemoryStorage) GetMethods() (map[string]int, error)
- func (ms *MemoryStorage) GetRecent(count int) ([]*LogEntry, error)
- func (ms *MemoryStorage) GetStats() (map[string]interface{}, error)
- func (ms *MemoryStorage) GetStatusCodes() (map[int]int, error)
- func (ms *MemoryStorage) ImportEntries(entries []*LogEntry) error
- func (ms *MemoryStorage) Save(entry *LogEntry) error
- func (ms *MemoryStorage) Search(keyword string, page, pageSize int) ([]*LogEntry, int, error)
- type Pagination
- type ProcessLogger
- func (p *ProcessLogger) EndProcess(status string) error
- func (p *ProcessLogger) Error(msg any, fields ...map[string]interface{})
- func (p *ProcessLogger) GetLevel() LogLevel
- func (p *ProcessLogger) GetProcessID() string
- func (p *ProcessLogger) GetProcessName() string
- func (p *ProcessLogger) GetProcessType() string
- func (p *ProcessLogger) Info(msg any, fields ...map[string]interface{})
- func (p *ProcessLogger) SetProcessInfo(info map[string]interface{})
- func (p *ProcessLogger) Warn(msg any, fields ...map[string]interface{})
- func (p *ProcessLogger) WithFields(fields map[string]interface{}) LoggerInterface
- type ProcessLoggerInterface
- type QueryManager
- func (qm *QueryManager) Cleanup(before time.Time) error
- func (qm *QueryManager) Export(format string, options QueryOptions) ([]byte, error)
- func (qm *QueryManager) GetActiveStreamingRequests(page, pageSize int) (*QueryResult, error)
- func (qm *QueryManager) GetByID(id string) (*LogEntry, error)
- func (qm *QueryManager) GetByIsStreaming(isStreaming bool, page, pageSize int) (*QueryResult, error)
- func (qm *QueryManager) GetByMethod(method string, page, pageSize int) (*QueryResult, error)
- func (qm *QueryManager) GetByStatusCode(statusCode int, page, pageSize int) (*QueryResult, error)
- func (qm *QueryManager) GetByStreamingStatus(streamingStatus string, page, pageSize int) (*QueryResult, error)
- func (qm *QueryManager) GetByTimeRange(startTime, endTime time.Time, page, pageSize int) (*QueryResult, error)
- func (qm *QueryManager) GetByURL(urlPattern string, page, pageSize int) (*QueryResult, error)
- func (qm *QueryManager) GetErrors(page, pageSize int) (*QueryResult, error)
- func (qm *QueryManager) GetFilterOptions() map[string]interface{}
- func (qm *QueryManager) GetInactiveStreamingRequests(page, pageSize int) (*QueryResult, error)
- func (qm *QueryManager) GetNonStreamingRequests(page, pageSize int) (*QueryResult, error)
- func (qm *QueryManager) GetRecent(limit int) ([]*LogEntry, error)
- func (qm *QueryManager) GetSlowRequests(threshold time.Duration, page, pageSize int) (*QueryResult, error)
- func (qm *QueryManager) GetStats() (map[string]interface{}, error)
- func (qm *QueryManager) GetStreamingRequests(page, pageSize int) (*QueryResult, error)
- func (qm *QueryManager) Query(options QueryOptions) (*QueryResult, error)
- func (qm *QueryManager) Search(keyword string, page, pageSize int) (*QueryResult, error)
- type QueryOptions
- type QueryResult
- type Storage
- type StreamingChunk
- type TemplateData
Constants ¶
const ( ProcessStatusCompleted = "completed" // 进程正常完成 ProcessStatusFailed = "failed" // 进程执行失败 ProcessStatusCancelled = "cancelled" // 进程被取消 )
进程状态常量定义
Variables ¶
This section is empty.
Functions ¶
func GenerateID ¶
func GenerateID() string
GenerateID 生成唯一请求标识 使用纳秒时间戳和进程ID确保唯一性,经过SM4加密后输出,密文结果不包含=字符
Types ¶
type Config ¶
type Config struct {
Enabled bool `json:"enabled" default:"true" preserve:"true"` // 是否启用调试器
MaxBodySize int64 `json:"max_body_size" default:"1024"` // 最大请求/响应体大小(KB),默认1MB
RetentionPeriod time.Duration `json:"retention_period" default:"168h"` // 日志保留期限,默认7天
Level LogLevel `json:"level" default:"3"` // 日志级别:LevelWarn
MaxRecords int `json:"max_records" default:"150"` // 最大记录数量,默认150条
EnableCallerInfo bool `json:"enable_caller_info" default:"true"` // 是否启用调用位置信息,默认开启,关闭可提高高并发场景下的性能
// 过滤配置
SkipPaths []string `json:"skip_paths" default:""` // 跳过的路径(如静态文件:"/static/,/favicon.ico")
SkipMethods []string `json:"skip_methods" default:"OPTIONS"` // 跳过的HTTP方法
AutoSkipStatic bool `json:"auto_skip_static" default:"true" preserve:"true"` // 是否自动跳过静态资源请求
StaticExtensions []string `` // 静态资源扩展名列表
/* 138-byte string literal not displayed */
// 采样配置
SampleRate float64 `json:"sample_rate" default:"1.0"` // 采样率(0-1之间),默认记录所有请求
// IP访问控制配置
AllowedIPs []string `json:"allowed_ips" default:""` // 允许访问的IP白名单,空数组表示不限制
UseCDN bool `json:"use_cdn" default:"false" preserve:"true"` // 是否使用CDN,影响真实IP获取方式
// 流式请求配置
EnableStreamingSupport bool `json:"enable_streaming_support" default:"false" preserve:"true"` // 是否启用流式请求支持
StreamingChunkSize int64 `json:"streaming_chunk_size" default:"1024"` // 流式响应分块大小(KB),默认1MB,0表示无限制
MaxStreamingChunks int `json:"max_streaming_chunks" default:"10"` // 最大流式响应分块数量,默认10个,0表示无限制
MaxStreamingMemory int64 `json:"max_streaming_memory" default:"10485760"` // 流式响应最大内存使用量(字节),默认10MB,0表示无限制
// Multipart请求配置
EnableMultipartSupport bool `json:"enable_multipart_support" default:"true" preserve:"true"` // 是否启用multipart请求支持
MultipartMaxPartSize int64 `json:"multipart_max_part_size" default:"64"` // multipart单个部分最大大小(KB),默认64KB
MultipartSkipFiles bool `json:"multipart_skip_files" default:"false" preserve:"true"` // 是否跳过文件内容记录,只记录元数据
MultipartPreserveState bool `json:"multipart_preserve_state" default:"true" preserve:"true"` // 是否保持Gin上下文状态,避免破坏后续中间件
// 中间件执行顺序配置
MiddlewareOrder string `json:"middleware_order" default:"normal"` // 中间件执行顺序:normal(正常)、early(优先)、late(最后)
// 核心组件配置 - 必须传入实例化的存储器
Storage Storage `json:"-"` // 存储实现(必须传入实例化的存储器)
Logger LoggerInterface `json:"-"` // 日志记录器(推荐直接传入实例化的日志记录器)
// 主进程日志配置
EnableMainLogger bool `json:"enable_main_logger" default:"false"` // 是否启用主进程日志
MainLogPath string `json:"main_log_path" default:"./runtime/logs/"` // 主进程日志文件路径
MainLogSplitMode string `json:"main_log_split_mode" default:"size"` // 日志分割模式:size(按大小)、date(按日期)
MainLogMaxSize int64 `json:"main_log_max_size" default:"100"` // 日志文件最大大小(MB),按大小分割时有效
MainLogMaxBackups int `json:"main_log_max_backups" default:"7"` // 最大备份文件数量
MainLogCompress bool `json:"main_log_compress" default:"false"` // 是否压缩备份日志
}
Config 调试器配置结构
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig 返回默认配置 使用helper.CheckAndSetDefault方法设置默认值,符合jcbaseGo规范
type Controller ¶
type Controller struct {
// contains filtered or unexported fields
}
Controller 调试器控制器结构
func NewController ¶
func NewController(debugger *Debugger, router *gin.Engine, config *ControllerConfig) *Controller
NewController 创建新的调试器控制器
func (*Controller) RegisterRoutes ¶
func (c *Controller) RegisterRoutes(router *gin.Engine)
RegisterRoutes 手动注册路由到指定的Gin引擎 用于在初始化时没有传入路由组的情况
type ControllerConfig ¶
type ControllerConfig struct {
BasePath string `json:"base_path" default:"/jcbase/debug"` // 基础路径,默认为 "/jcbase/debug"
UseCDN bool `json:"use_cdn" default:"false"` // 是否使用CDN,默认为 false
Title string `json:"title" default:"调试器"` // 页面标题,默认为 "调试器"
PageSize int `json:"page_size" default:"20"` // 页面大小,默认为 20
}
ControllerConfig 控制器配置
type DatabaseStorage ¶
type DatabaseStorage struct {
// contains filtered or unexported fields
}
DatabaseStorage 数据库存储器实现 使用GORM将调试日志保存到数据库中
func NewDatabaseStorage ¶
NewDatabaseStorage 创建新的数据库存储器 db: GORM数据库连接 maxSize: 最大存储条目数(0表示无限制) tableName: 数据表名(可选,默认为"debug_logs")
func (*DatabaseStorage) Cleanup ¶
func (ds *DatabaseStorage) Cleanup(before time.Time) error
Cleanup 清理过期日志
func (*DatabaseStorage) CreateIndexes ¶
func (ds *DatabaseStorage) CreateIndexes() error
CreateIndexes 创建索引(优化查询性能)
func (*DatabaseStorage) FindAll ¶
func (ds *DatabaseStorage) FindAll(page, pageSize int, filters map[string]interface{}) ([]*LogEntry, int, error)
FindAll 查找所有日志条目,支持分页和过滤
func (*DatabaseStorage) FindByID ¶
func (ds *DatabaseStorage) FindByID(id string) (*LogEntry, error)
FindByID 根据ID查找日志条目
func (*DatabaseStorage) GetMethods ¶
func (ds *DatabaseStorage) GetMethods() (map[string]int, error)
GetMethods 获取所有HTTP方法统计
func (*DatabaseStorage) GetStats ¶
func (ds *DatabaseStorage) GetStats() (map[string]interface{}, error)
GetStats 获取存储统计信息
func (*DatabaseStorage) GetStatusCodes ¶
func (ds *DatabaseStorage) GetStatusCodes() (map[int]int, error)
GetStatusCodes 获取所有状态码统计
func (*DatabaseStorage) Save ¶
func (ds *DatabaseStorage) Save(entry *LogEntry) error
Save 保存日志条目到数据库
type Debugger ¶
type Debugger struct {
// contains filtered or unexported fields
}
Debugger 调试器主结构
func NewProductionDebugger ¶
NewProductionDebugger 创建生产环境调试器实例 使用文件存储,适合生产环境
func NewSimpleDebugger ¶
NewSimpleDebugger 创建简单的调试器实例 使用默认配置,适合快速开始
func NewWithCustomStorage ¶
NewWithCustomStorage 创建使用自定义存储器的调试器 适用于需要自定义存储逻辑的场景
func NewWithFileStorage ¶
NewWithFileStorage 创建使用文件存储器的调试器 适用于生产环境,日志会持久化到文件系统
func NewWithMemoryStorage ¶
NewWithMemoryStorage 创建使用内存存储器的调试器 适用于开发和测试环境
func (*Debugger) EndProcess ¶ added in v0.13.3
EndProcess 结束进程记录 通过进程ID结束指定的进程记录,记录进程的结束时间和状态 该方法应在进程执行完成时调用,以确保记录完整的执行时间线
参数:
processID: 进程ID,由StartProcess方法返回 status: 进程结束状态,使用预定义的常量:ProcessStatusCompleted、ProcessStatusFailed、ProcessStatusCancelled
返回值:
error: 错误信息,当进程记录不存在、类型不匹配或保存失败时返回错误
示例:
err := dbg.EndProcess("process-123456", ProcessStatusCompleted)
if err != nil {
// 处理错误
}
func (*Debugger) GetController ¶
func (d *Debugger) GetController() *Controller
GetController 获取控制器实例
func (*Debugger) GetLogger ¶
func (d *Debugger) GetLogger() LoggerInterface
GetLogger 获取调试器的日志记录器 可以在控制器中通过此方法获取Logger实例来记录日志
func (*Debugger) GetLoggerWithFields ¶
func (d *Debugger) GetLoggerWithFields(fields map[string]interface{}) LoggerInterface
GetLoggerWithFields 获取带有指定字段的日志记录器
func (*Debugger) GetMainLogger ¶ added in v0.13.15
func (d *Debugger) GetMainLogger() LoggerInterface
GetMainLogger 获取主进程日志记录器 可以在应用程序的任何地方通过此方法获取主进程日志记录器实例
func (*Debugger) GetMainLoggerWithFields ¶ added in v0.13.15
func (d *Debugger) GetMainLoggerWithFields(fields map[string]interface{}) LoggerInterface
GetMainLoggerWithFields 获取带有指定字段的主进程日志记录器 可以在应用程序的任何地方通过此方法获取带有指定字段的主进程日志记录器实例
func (*Debugger) GetProcessLogger ¶ added in v0.13.3
func (d *Debugger) GetProcessLogger(processID string) (ProcessLoggerInterface, error)
GetProcessLogger 获取进程级日志记录器 通过进程ID获取已存在的进程记录器,用于在进程执行过程中获取记录器实例 该方法适用于需要跨函数或协程共享同一进程记录器的场景
参数:
processID: 进程ID,由StartProcess方法返回
返回值:
ProcessLoggerInterface: 进程级日志记录器实例 error: 错误信息,当进程记录不存在、类型不匹配或进程已结束时返回错误
示例:
logger, err := dbg.GetProcessLogger("process-123456")
if err != nil {
// 处理错误
}
logger.Info("继续处理任务")
func (*Debugger) GetProcessRecords ¶ added in v0.13.3
func (d *Debugger) GetProcessRecords(page, pageSize int, filters map[string]interface{}) ([]*LogEntry, int, error)
GetProcessRecords 获取进程记录列表 支持分页和过滤查询进程记录,可用于监控和分析进程执行情况
参数:
page: 页码,从1开始 pageSize: 每页记录数 filters: 过滤条件,支持record_type/process_name/process_id等字段
返回值:
[]*LogEntry: 进程记录列表 int: 总记录数 error: 错误信息
示例:
records, total, err := dbg.GetProcessRecords(1, 20, map[string]interface{}{
"process_name": "数据同步任务",
})
func (*Debugger) Middleware ¶
func (d *Debugger) Middleware() gin.HandlerFunc
Middleware 创建Gin中间件 用于拦截HTTP请求并记录调试信息
func (*Debugger) RegisterRoutes ¶
RegisterRoutes 手动注册路由到指定的Gin引擎 只支持 *gin.Engine 类型,使用更简洁
func (*Debugger) SetSessionData ¶
SetSessionData 设置会话数据(供外部调用)
func (*Debugger) StartProcess ¶ added in v0.13.3
func (d *Debugger) StartProcess(processName, processType string) ProcessLoggerInterface
StartProcess 开始进程记录 创建一个进程级日志记录器,用于在进程中记录不同级别的debugger日志 该方法适用于后台任务、批处理作业、定时任务等非HTTP进程场景
参数:
processName: 进程名称,用于标识进程用途(如"数据同步任务") processType: 进程类型,可选值:background/worker/cron/batch等
返回值:
ProcessLoggerInterface: 进程级日志记录器实例
示例:
logger := dbg.StartProcess("数据同步任务", "batch")
defer dbg.EndProcess(logger.GetProcessID(), "completed")
func (*Debugger) WithController ¶
func (d *Debugger) WithController(router *gin.Engine, config *ControllerConfig) *Debugger
WithController 为调试器添加控制器支持 router: Gin引擎,用于注册调试器页面路由 config: 控制器配置(可选)
type DefaultLogger ¶
type DefaultLogger struct {
// contains filtered or unexported fields
}
DefaultLogger 调试器内置的日志记录器实现(默认实现) 不能直接创建DefaultLogger实例,只能通过NewDefaultLogger创建
func (*DefaultLogger) Error ¶
func (l *DefaultLogger) Error(msg any, fields ...map[string]interface{})
Error 记录错误级别日志
func (*DefaultLogger) GetLevel ¶ added in v0.13.2
func (l *DefaultLogger) GetLevel() LogLevel
GetLevel 获取当前日志记录器的日志级别
func (*DefaultLogger) Info ¶
func (l *DefaultLogger) Info(msg any, fields ...map[string]interface{})
Info 记录信息级别日志
func (*DefaultLogger) Warn ¶
func (l *DefaultLogger) Warn(msg any, fields ...map[string]interface{})
Warn 记录警告级别日志
func (*DefaultLogger) WithFields ¶
func (l *DefaultLogger) WithFields(fields map[string]interface{}) LoggerInterface
WithFields 创建带有字段的日志记录器
type DetailView ¶
type DetailView struct {
LogEntry *LogEntry `json:"log_entry"` // 原始日志条目
// 格式化后的内容
FormattedRequestHeaders string `json:"formatted_request_headers"` // 格式化请求头
FormattedResponseHeaders string `json:"formatted_response_headers"` // 格式化响应头
FormattedRequestBody string `json:"formatted_request_body"` // 格式化请求体
FormattedResponseBody string `json:"formatted_response_body"` // 格式化响应体
FormattedSessionData string `json:"formatted_session_data"` // 格式化会话数据
FormattedQueryParams string `json:"formatted_query_params"` // 格式化查询参数
// 进程记录专用格式化字段
FormattedProcessInfo string `json:"formatted_process_info"` // 格式化进程信息
FormattedEndTime string `json:"formatted_end_time"` // 格式化结束时间
FormattedProcessStatus string `json:"formatted_process_status"` // 格式化进程状态
// 统计信息
RequestSize int `json:"request_size"` // 请求大小(字节)
ResponseSize int `json:"response_size"` // 响应大小(字节)
// 时间信息
FormattedTimestamp string `json:"formatted_timestamp"` // 格式化时间戳
FormattedDuration string `json:"formatted_duration"` // 格式化持续时间
// 相关日志
RelatedEntries []*LogEntry `json:"related_entries"` // 相关日志条目
}
DetailView 详情视图 包含日志条目的完整信息和格式化后的内容
type DetailViewer ¶
type DetailViewer struct {
// contains filtered or unexported fields
}
DetailViewer 日志详情查看器 提供丰富的日志详情展示功能,支持格式化显示请求和响应信息
func NewDetailViewer ¶
func NewDetailViewer(queryManager *QueryManager) *DetailViewer
NewDetailViewer 创建新的详情查看器 queryManager: 查询管理器实例
func (*DetailViewer) CompareEntries ¶
func (dv *DetailViewer) CompareEntries(id1, id2 string) (map[string]interface{}, error)
CompareEntries 比较两个日志条目
func (*DetailViewer) GetDetail ¶
func (dv *DetailViewer) GetDetail(id string) (*DetailView, error)
GetDetail 获取日志详情 id: 日志条目ID
func (*DetailViewer) GetDetailHTML ¶
func (dv *DetailViewer) GetDetailHTML(id string) (string, error)
GetDetailHTML 获取HTML格式的详情
func (*DetailViewer) GetDetailJSON ¶
func (dv *DetailViewer) GetDetailJSON(id string) ([]byte, error)
GetDetailJSON 获取JSON格式的详情
type FileStorage ¶
type FileStorage struct {
// contains filtered or unexported fields
}
FileStorage 文件存储器实现 将调试日志保存到文件系统中
func NewFileStorage ¶
func NewFileStorage(basePath string, maxSize int) (*FileStorage, error)
NewFileStorage 创建新的文件存储器 basePath: 文件存储的基础路径 maxSize: 最大存储条目数(0表示无限制)
func (*FileStorage) ExportAll ¶
func (fs *FileStorage) ExportAll(outputPath string) error
ExportAll 导出所有日志到单个文件
func (*FileStorage) FindAll ¶
func (fs *FileStorage) FindAll(page, pageSize int, filters map[string]interface{}) ([]*LogEntry, int, error)
FindAll 查找所有日志条目,支持分页和过滤 优化性能:实现真正的分页查询,避免全量文件读取 该方法提供统一的查询接口,适用于HTTP记录和进程记录的检索
参数:
page: 页码(从1开始) pageSize: 每页显示数量 filters: 过滤条件映射,支持record_type、method、status_code、url、process_name、process_id等字段
返回值:
[]*LogEntry: 符合条件的日志条目列表(按时间倒序排列) int: 符合条件的总条目数 error: 如果查询过程中发生错误返回错误信息,否则返回nil
优化逻辑:
- 首先统计符合条件的文件总数(不读取文件内容)
- 按文件名时间戳排序,只读取当前页需要的文件
- 避免全量文件读取,减少I/O操作和内存占用
func (*FileStorage) FindByID ¶
func (fs *FileStorage) FindByID(id string) (*LogEntry, error)
FindByID 根据ID查找日志条目
func (*FileStorage) GetMethods ¶
func (fs *FileStorage) GetMethods() (map[string]int, error)
GetMethods 获取HTTP方法统计
func (*FileStorage) GetStats ¶
func (fs *FileStorage) GetStats() (map[string]interface{}, error)
GetStats 获取存储统计信息 计算文件存储的详细统计信息,包括存储大小、请求数量、错误率等指标 该方法提供与内存存储器相同的统计接口,确保存储组件的一致性
返回值:
map[string]interface{}: 统计信息映射,包含以下字段:
- total_requests: 总请求数(HTTP记录和进程记录的总数)
- storage_size: 存储大小(格式化显示,单位KB)
- max_size: 最大存储条目数
- storage_type: 存储类型(固定为"file")
- storage_path: 存储路径
- avg_duration: 平均响应时间(仅当有记录时计算)
- error_rate: 错误率(仅当有记录时计算)
- error_count: 错误数量(仅当有记录时计算)
error: 如果获取统计信息失败返回错误
统计计算说明:
- 存储大小计算采用精确算法,与内存存储器和单个条目计算逻辑保持一致
- 统计信息包含所有有效的日志文件(HTTP记录和进程记录)
- 跳过读取失败的文件,确保统计的准确性
func (*FileStorage) GetStatusCodes ¶
func (fs *FileStorage) GetStatusCodes() (map[int]int, error)
GetStatusCodes 获取状态码统计
func (*FileStorage) ImportFromFile ¶
func (fs *FileStorage) ImportFromFile(filePath string) error
ImportFromFile 从文件导入日志
func (*FileStorage) Save ¶
func (fs *FileStorage) Save(entry *LogEntry) error
Save 保存日志条目到文件 每个日志条目保存为一个独立的JSON文件
func (*FileStorage) Search ¶
Search 搜索日志内容 Search 搜索日志内容 优化性能:实现真正的分页搜索,避免全量文件读取 在日志条目的多个字段中进行全文搜索,支持HTTP记录和进程记录的关键词检索 该方法提供不区分大小写的搜索功能,适用于快速查找特定内容的日志记录
参数:
keyword: 搜索关键词,支持在进程名称、URL、请求体、响应体、错误信息等字段中搜索 page: 页码(从1开始) pageSize: 每页显示数量
返回值:
[]*LogEntry: 包含关键词的日志条目列表(按时间倒序排列) int: 包含关键词的总条目数 error: 如果搜索过程中发生错误返回错误信息,否则返回nil
优化逻辑:
- 首先统计符合条件的文件总数(使用快速文件头读取)
- 按文件名时间戳排序,只读取当前页需要的文件
- 避免全量文件读取,减少I/O操作和内存占用
type LogEntry ¶
type LogEntry struct {
ID string `json:"id"` // 日志唯一标识
Timestamp time.Time `json:"timestamp"` // 请求/进程开始时间戳
Method string `json:"method"` // HTTP方法(HTTP记录专用)
URL string `json:"url"` // 请求URL(HTTP记录专用)
StatusCode int `json:"status_code"` // HTTP状态码(HTTP记录专用)
Duration time.Duration `json:"duration"` // 处理耗时
ClientIP string `json:"client_ip"` // 客户端IP(HTTP记录专用)
UserAgent string `json:"user_agent"` // 用户代理(HTTP记录专用)
Host string `json:"host"` // 请求域名(HTTP记录专用)
RequestID string `json:"request_id"` // 请求ID(用于追踪)
// 记录类型标识
RecordType string `json:"record_type" default:"http"` // 记录类型:http/process
// 进程记录专用字段
ProcessID string `json:"process_id,omitempty"` // 进程唯一标识
ProcessName string `json:"process_name,omitempty"` // 进程名称
ProcessType string `json:"process_type,omitempty"` // 进程类型(background/worker/cron等)
EndTime time.Time `json:"end_time,omitempty"` // 进程结束时间
Status string `json:"status,omitempty"` // 进程状态(running/completed/failed)
// 请求信息(HTTP记录专用)
RequestHeaders map[string]string `json:"request_headers"` // 请求头
QueryParams map[string]string `json:"query_params"` // 查询参数
RequestBody string `json:"request_body"` // 请求体内容
// 响应信息(HTTP记录专用)
ResponseHeaders map[string]string `json:"response_headers"` // 响应头
ResponseBody string `json:"response_body"` // 响应体内容
// 会话数据(可选)
SessionData map[string]interface{} `json:"session_data,omitempty"` // 会话数据
// 错误信息
Error string `json:"error,omitempty"` // 错误信息
// Logger日志信息(新增)
LoggerLogs []LoggerLog `json:"logger_logs,omitempty"` // 通过logger记录的日志
// 流式响应元数据(新增)
IsStreamingResponse bool `json:"is_streaming_response,omitempty"` // 是否为流式响应
StreamingChunks int `json:"streaming_chunks,omitempty"` // 流式响应分块数量
StreamingChunkSize int `json:"streaming_chunk_size,omitempty"` // 流式响应分块大小限制(字节)
MaxStreamingChunks int `json:"max_streaming_chunks,omitempty"` // 流式响应最大分块数量限制
StreamingData string `json:"streaming_data,omitempty"` // 流式响应数据摘要(格式化显示)
// 存储大小(计算字段,不持久化到存储)
StorageSize string `json:"storage_size,omitempty"` // 存储大小(格式化显示)
}
LogEntry 调试日志条目结构 用于记录单个HTTP请求或进程的完整调试信息
func (*LogEntry) CalculateStorageSize ¶
CalculateStorageSize 计算日志条目的存储大小并格式化显示 计算内容包括:基本字段、请求体、响应体、请求头、响应头、查询参数、会话数据等 与总存储计算逻辑保持一致
type LogEntryModel ¶
type LogEntryModel struct {
ID string `gorm:"column:id;type:VARCHAR(64);primaryKey" json:"id"`
Timestamp time.Time `gorm:"column:timestamp;type:DATETIME;index" json:"timestamp"`
Method string `gorm:"column:method;type:VARCHAR(10);index" json:"method"`
URL string `gorm:"column:url;type:TEXT" json:"url"`
StatusCode int `gorm:"column:status_code;type:INT;index" json:"status_code"`
Duration int64 `gorm:"column:duration;type:BIGINT" json:"duration"` // 存储纳秒数
ClientIP string `gorm:"column:client_ip;type:VARCHAR(45)" json:"client_ip"`
UserAgent string `gorm:"column:user_agent;type:TEXT" json:"user_agent"`
RequestID string `gorm:"column:request_id;type:VARCHAR(64);index" json:"request_id"`
// 记录类型和进程相关字段
RecordType string `gorm:"column:record_type;type:VARCHAR(20);index" json:"record_type"` // 记录类型:http/process
ProcessID string `gorm:"column:process_id;type:VARCHAR(64);index" json:"process_id"` // 进程唯一标识
ProcessName string `gorm:"column:process_name;type:VARCHAR(255)" json:"process_name"` // 进程名称
ProcessType string `gorm:"column:process_type;type:VARCHAR(50)" json:"process_type"` // 进程类型
EndTime time.Time `gorm:"column:end_time;type:DATETIME" json:"end_time"` // 进程结束时间
Status string `gorm:"column:status;type:VARCHAR(20);index" json:"status"` // 进程状态
// JSON格式存储的字段
RequestHeaders string `gorm:"column:request_headers;type:JSON" json:"request_headers"`
QueryParams string `gorm:"column:query_params;type:JSON" json:"query_params"`
RequestBody string `gorm:"column:request_body;type:LONGTEXT" json:"request_body"`
ResponseHeaders string `gorm:"column:response_headers;type:JSON" json:"response_headers"`
ResponseBody string `gorm:"column:response_body;type:LONGTEXT" json:"response_body"`
SessionData string `gorm:"column:session_data;type:JSON" json:"session_data"`
Error string `gorm:"column:error;type:TEXT" json:"error"`
// 索引字段
URLHash string `gorm:"column:url_hash;type:VARCHAR(32);index" json:"url_hash"` // URL的MD5哈希,用于快速搜索
// 流式响应相关字段
IsStreamingResponse bool `gorm:"column:is_streaming_response;type:BOOLEAN;index" json:"is_streaming_response"` // 是否为流式响应
StreamingChunks int `gorm:"column:streaming_chunks;type:INT" json:"streaming_chunks"` // 流式响应分块数量
StreamingChunkSize int `gorm:"column:streaming_chunk_size;type:INT" json:"streaming_chunk_size"` // 流式响应分块大小限制(字节)
MaxStreamingChunks int `gorm:"column:max_streaming_chunks;type:INT" json:"max_streaming_chunks"` // 流式响应最大分块数量限制
StreamingData string `gorm:"column:streaming_data;type:TEXT" json:"streaming_data"` // 流式响应数据摘要(格式化显示)
}
LogEntryModel 数据库模型结构 对应数据库中的日志条目表,支持HTTP记录和进程记录
type LogLevel ¶ added in v0.13.8
type LogLevel int
type LoggerInterface ¶
type LoggerInterface interface {
// Info 记录信息级别日志
Info(msg any, fields ...map[string]interface{})
// Warn 记录警告级别日志
Warn(msg any, fields ...map[string]interface{})
// Error 记录错误级别日志
Error(msg any, fields ...map[string]interface{})
// WithFields 创建带有字段的日志记录器
WithFields(fields map[string]interface{}) LoggerInterface
// GetLevel 获取当前日志记录器的日志级别
GetLevel() LogLevel
}
LoggerInterface 日志记录器接口 支持不同级别的日志记录,可以在控制器中直接使用
func GetLoggerFromContext ¶
func GetLoggerFromContext(c *gin.Context) LoggerInterface
GetLoggerFromContext 从Gin上下文中获取Logger实例 控制器可以通过此函数获取Logger来记录日志
func NewDefaultLogger ¶ added in v0.13.7
func NewDefaultLogger(debugger *Debugger) LoggerInterface
NewDefaultLogger 创建默认日志记录器实例
func NewMainLogger ¶ added in v0.13.15
func NewMainLogger(debugger *Debugger) LoggerInterface
NewMainLogger 创建新的主进程日志记录器 该方法会创建主进程日志记录器,适用于需要持久化保存的应用程序级日志 支持按日期或大小分割日志文件
参数:
debugger: 调试器实例,用于配置管理
返回值:
LoggerInterface: 主进程日志记录器实例
示例:
mainLogger := NewMainLogger(dbg)
mainLogger.Info("应用程序启动")
type LoggerLog ¶
type LoggerLog struct {
Timestamp time.Time `json:"timestamp"` // 日志时间戳
Level LogLevel `json:"level"` // 日志级别:debug/info/warn/error
Message string `json:"message"` // 日志消息
Fields map[string]interface{} `json:"fields"` // 日志附加字段
// 位置信息字段(新增)
FileName string `json:"file_name,omitempty"` // 文件名
Line int `json:"line,omitempty"` // 行号
Function string `json:"function,omitempty"` // 函数名
}
LoggerLog 记录通过logger打印的日志信息
type MainLogger ¶ added in v0.13.15
type MainLogger struct {
// contains filtered or unexported fields
}
func (*MainLogger) Error ¶ added in v0.13.15
func (l *MainLogger) Error(msg any, fields ...map[string]interface{})
Error 记录错误级别日志
func (*MainLogger) GetLevel ¶ added in v0.13.15
func (l *MainLogger) GetLevel() LogLevel
GetLevel 获取当前日志记录器的日志级别
func (*MainLogger) Info ¶ added in v0.13.15
func (l *MainLogger) Info(msg any, fields ...map[string]interface{})
Info 记录信息级别日志
func (*MainLogger) Warn ¶ added in v0.13.15
func (l *MainLogger) Warn(msg any, fields ...map[string]interface{})
Warn 记录警告级别日志
func (*MainLogger) WithFields ¶ added in v0.13.15
func (l *MainLogger) WithFields(fields map[string]interface{}) LoggerInterface
WithFields 创建带有字段的日志记录器
type MemoryStorage ¶
type MemoryStorage struct {
// contains filtered or unexported fields
}
MemoryStorage 内存存储器实现 将调试日志保存在内存中,适合开发环境使用
func NewMemoryStorage ¶
func NewMemoryStorage(maxSize ...int) (*MemoryStorage, error)
NewMemoryStorage 创建新的内存存储器 maxSize: 最大存储条目数(0表示无限制)
func (*MemoryStorage) Cleanup ¶
func (ms *MemoryStorage) Cleanup(before time.Time) error
Cleanup 清理过期日志
func (*MemoryStorage) ExportAll ¶
func (ms *MemoryStorage) ExportAll() ([]*LogEntry, error)
ExportAll 导出所有日志到内存(返回副本)
func (*MemoryStorage) FindAll ¶
func (ms *MemoryStorage) FindAll(page, pageSize int, filters map[string]interface{}) ([]*LogEntry, int, error)
FindAll 查找所有日志条目,支持分页和过滤 优化性能:实现真正的分页查询,避免全量数据遍历 优化并发:减少锁持有时间,提高并发性能 该方法提供统一的查询接口,适用于HTTP记录和进程记录的检索
参数:
page: 页码(从1开始) pageSize: 每页显示数量 filters: 过滤条件映射,支持record_type、method、status_code、url、process_name、process_id等字段
返回值:
[]*LogEntry: 符合条件的日志条目列表(按时间倒序排列) int: 符合条件的总条目数 error: 如果查询过程中发生错误返回错误信息,否则返回nil
优化逻辑:
- 首先收集所有有效的日志条目(非nil)
- 计算符合条件的总条目数
- 按时间倒序排序后,只返回当前页需要的数据
- 支持空过滤条件,返回分页数据
- 减少锁持有时间,提高并发性能
func (*MemoryStorage) FindByID ¶
func (ms *MemoryStorage) FindByID(id string) (*LogEntry, error)
FindByID 根据ID查找日志条目
func (*MemoryStorage) GetByTimeRange ¶
func (ms *MemoryStorage) GetByTimeRange(startTime, endTime time.Time) ([]*LogEntry, error)
GetByTimeRange 根据时间范围获取日志条目
func (*MemoryStorage) GetMethods ¶
func (ms *MemoryStorage) GetMethods() (map[string]int, error)
GetMethods 获取所有HTTP方法统计
func (*MemoryStorage) GetRecent ¶
func (ms *MemoryStorage) GetRecent(count int) ([]*LogEntry, error)
GetRecent 获取最近的日志条目
func (*MemoryStorage) GetStats ¶
func (ms *MemoryStorage) GetStats() (map[string]interface{}, error)
GetStats 获取存储统计信息
func (*MemoryStorage) GetStatusCodes ¶
func (ms *MemoryStorage) GetStatusCodes() (map[int]int, error)
GetStatusCodes 获取所有状态码统计
func (*MemoryStorage) ImportEntries ¶
func (ms *MemoryStorage) ImportEntries(entries []*LogEntry) error
ImportEntries 导入日志条目
func (*MemoryStorage) Save ¶
func (ms *MemoryStorage) Save(entry *LogEntry) error
Save 保存日志条目到内存 将HTTP记录或进程记录保存到内存存储中,支持自动清理和更新机制 该方法确保存储的线程安全性,并维护ID索引以提高查询性能
参数:
entry: 要保存的日志条目,包含HTTP记录或进程记录的完整信息
返回值:
error: 如果保存过程中发生错误返回错误信息,否则返回nil
保存逻辑:
- 如果条目ID已存在,则更新现有条目(支持进程记录的动态更新)
- 使用环形缓冲区存储条目,当超过最大存储限制时,自动覆盖最旧的条目(FIFO策略)
- 维护ID到索引的映射,提高FindByID等操作的性能
- 使用读写锁确保多线程环境下的数据一致性
- 时间复杂度O(1),避免了重建索引的开销
func (*MemoryStorage) Search ¶
Search 搜索日志内容 优化性能:实现真正的分页搜索,避免全量数据遍历 优化并发:减少锁持有时间,提高并发性能 在日志条目的多个字段中进行全文搜索,支持HTTP记录和进程记录的关键词检索 该方法提供不区分大小写的搜索功能,适用于快速查找特定内容的日志记录
参数:
keyword: 搜索关键词,支持在进程名称、URL、请求体、响应体、错误信息等字段中搜索 page: 页码(从1开始) pageSize: 每页显示数量
返回值:
[]*LogEntry: 包含关键词的日志条目列表(按时间倒序排列) int: 包含关键词的总条目数 error: 如果搜索过程中发生错误返回错误信息,否则返回nil
优化逻辑:
- 首先收集所有有效的日志条目(非nil)
- 搜索符合条件的条目
- 按时间倒序排序后,只返回当前页需要的数据
- 减少锁持有时间,提高并发性能
搜索范围:
- 进程名称(process_name)
- URL路径(url)
- 请求体(request_body)
- 响应体(response_body)
- 错误信息(error)
- 请求头(request_headers)的所有值
- 响应头(response_headers)的所有值
type Pagination ¶
type Pagination struct {
Page int // 当前页码
PageSize int // 每页大小
Total int // 总记录数
TotalPages int // 总页数
HasPrev bool // 是否有上一页
HasNext bool // 是否有下一页
PrevPage int // 上一页页码
NextPage int // 下一页页码
}
Pagination 分页信息
type ProcessLogger ¶ added in v0.13.3
type ProcessLogger struct {
// contains filtered or unexported fields
}
ProcessLogger 进程级日志记录器 用于在进程中记录不同级别的debugger日志,所有日志属于同一条进程记录 该记录器适用于后台任务、批处理作业、定时任务等非HTTP进程场景
func NewProcessLogger ¶ added in v0.13.3
func NewProcessLogger(debugger *Debugger, processName, processType string) *ProcessLogger
NewProcessLogger 创建新的进程级日志记录器 该方法会创建进程记录并初始化进程级日志记录器,适用于需要监控的非HTTP进程
参数:
debugger: 调试器实例,用于存储和配置管理 processName: 进程名称,用于标识进程用途(如"数据同步任务") processType: 进程类型,可选值:background/worker/cron/batch等
返回值:
*ProcessLogger: 进程级日志记录器实例
示例:
logger := NewProcessLogger(dbg, "数据同步任务", "batch")
defer logger.EndProcess("completed")
func (*ProcessLogger) EndProcess ¶ added in v0.13.3
func (p *ProcessLogger) EndProcess(status string) error
EndProcess 结束进程记录 结束当前进程记录,记录进程的结束时间、状态和所有收集的日志 该方法应在进程执行完成时调用,以确保记录完整的执行时间线
参数:
status: 进程结束状态,使用预定义的常量:ProcessStatusCompleted、ProcessStatusFailed、ProcessStatusCancelled
返回值:
error: 错误信息,当进程记录不存在或保存失败时返回错误
示例:
err := logger.EndProcess(ProcessStatusCompleted)
if err != nil {
// 处理错误
}
func (*ProcessLogger) Error ¶ added in v0.13.3
func (p *ProcessLogger) Error(msg any, fields ...map[string]interface{})
Error 记录错误级别日志 记录进程执行过程中发生的错误信息
参数:
msg: 日志消息,可以是字符串、结构体或实现了Stringer接口的类型 fields: 可选的附加字段,用于记录错误相关的详细信息
示例:
logger.Error("数据库连接失败", map[string]interface{}{"error": err.Error()})
func (*ProcessLogger) GetLevel ¶ added in v0.13.3
func (p *ProcessLogger) GetLevel() LogLevel
GetLevel 获取当前日志记录器的日志级别 返回当前调试器配置的日志级别
返回值:
LogLevel: 日志级别(LevelInfo/LevelWarn/LevelError/LevelSilent)
func (*ProcessLogger) GetProcessID ¶ added in v0.13.3
func (p *ProcessLogger) GetProcessID() string
GetProcessID 获取进程ID 返回当前进程的唯一标识符,可用于后续查询和监控
返回值:
string: 进程ID
示例:
processID := logger.GetProcessID()
func (*ProcessLogger) GetProcessName ¶ added in v0.13.3
func (p *ProcessLogger) GetProcessName() string
GetProcessName 获取进程名称 返回当前进程的名称,用于标识进程用途
返回值:
string: 进程名称
func (*ProcessLogger) GetProcessType ¶ added in v0.13.3
func (p *ProcessLogger) GetProcessType() string
GetProcessType 获取进程类型 返回当前进程的类型,如background/worker/cron等
返回值:
string: 进程类型
func (*ProcessLogger) Info ¶ added in v0.13.3
func (p *ProcessLogger) Info(msg any, fields ...map[string]interface{})
Info 记录信息级别日志 记录进程执行的关键信息,适用于监控和状态跟踪
参数:
msg: 日志消息,可以是字符串、结构体或实现了Stringer接口的类型 fields: 可选的附加字段,用于记录额外的状态信息
示例:
logger.Info("数据同步完成", map[string]interface{}{"processed": 1000})
func (*ProcessLogger) SetProcessInfo ¶ added in v0.13.3
func (p *ProcessLogger) SetProcessInfo(info map[string]interface{})
SetProcessInfo 设置进程信息 动态更新进程的附加信息,适用于进程执行过程中需要记录额外上下文信息的场景
参数:
info: 进程信息映射,可以包含任意键值对
示例:
logger.SetProcessInfo(map[string]interface{}{"progress": "50%", "current_file": "data.csv"})
func (*ProcessLogger) Warn ¶ added in v0.13.3
func (p *ProcessLogger) Warn(msg any, fields ...map[string]interface{})
Warn 记录警告级别日志 记录可能影响进程正常执行的警告信息
参数:
msg: 日志消息,可以是字符串、结构体或实现了Stringer接口的类型 fields: 可选的附加字段,用于记录警告相关的上下文信息
示例:
logger.Warn("磁盘空间不足", map[string]interface{}{"available": "1GB"})
func (*ProcessLogger) WithFields ¶ added in v0.13.3
func (p *ProcessLogger) WithFields(fields map[string]interface{}) LoggerInterface
WithFields 创建带有字段的日志记录器 创建一个新的日志记录器实例,继承当前记录器的所有字段并添加新字段
参数:
fields: 要添加的字段映射
返回值:
LoggerInterface: 新的日志记录器实例
示例:
subLogger := logger.WithFields(map[string]interface{}{"module": "data_processor"})
type ProcessLoggerInterface ¶ added in v0.13.3
type ProcessLoggerInterface interface {
LoggerInterface // 继承基础日志接口
// GetProcessID 获取进程ID
GetProcessID() string
// GetProcessName 获取进程名称
GetProcessName() string
// GetProcessType 获取进程类型
GetProcessType() string
// SetProcessInfo 设置进程信息
SetProcessInfo(info map[string]interface{})
// EndProcess 结束进程记录
EndProcess(status string) error
}
ProcessLoggerInterface 进程级日志记录器接口 提供进程级日志记录功能,继承基础日志接口并添加进程管理方法
type QueryManager ¶
type QueryManager struct {
// contains filtered or unexported fields
}
QueryManager 日志查询管理器 提供丰富的查询和过滤功能,支持多种查询条件组合
func NewQueryManager ¶
func NewQueryManager(storage Storage) *QueryManager
NewQueryManager 创建新的查询管理器 storage: 存储接口实例
func (*QueryManager) Cleanup ¶
func (qm *QueryManager) Cleanup(before time.Time) error
Cleanup 清理过期日志 before: 清理此时间之前的日志
func (*QueryManager) Export ¶
func (qm *QueryManager) Export(format string, options QueryOptions) ([]byte, error)
Export 导出日志数据 format: 导出格式(json, csv等)
func (*QueryManager) GetActiveStreamingRequests ¶ added in v0.13.5
func (qm *QueryManager) GetActiveStreamingRequests(page, pageSize int) (*QueryResult, error)
GetActiveStreamingRequests 获取活跃的流式请求日志
func (*QueryManager) GetByID ¶
func (qm *QueryManager) GetByID(id string) (*LogEntry, error)
GetByID 根据ID获取日志条目
func (*QueryManager) GetByIsStreaming ¶ added in v0.13.5
func (qm *QueryManager) GetByIsStreaming(isStreaming bool, page, pageSize int) (*QueryResult, error)
GetByIsStreaming 根据流式请求状态查询日志 isStreaming: 是否为流式请求(true/false)
func (*QueryManager) GetByMethod ¶
func (qm *QueryManager) GetByMethod(method string, page, pageSize int) (*QueryResult, error)
GetByMethod 根据HTTP方法查询日志
func (*QueryManager) GetByStatusCode ¶
func (qm *QueryManager) GetByStatusCode(statusCode int, page, pageSize int) (*QueryResult, error)
GetByStatusCode 根据状态码查询日志
func (*QueryManager) GetByStreamingStatus ¶ added in v0.13.5
func (qm *QueryManager) GetByStreamingStatus(streamingStatus string, page, pageSize int) (*QueryResult, error)
GetByStreamingStatus 根据流式请求活跃状态查询日志 streamingStatus: 流式请求状态("active" - 活跃, "inactive" - 非活跃)
func (*QueryManager) GetByTimeRange ¶
func (qm *QueryManager) GetByTimeRange(startTime, endTime time.Time, page, pageSize int) (*QueryResult, error)
GetByTimeRange 根据时间范围查询日志 startTime: 开始时间 endTime: 结束时间
func (*QueryManager) GetByURL ¶
func (qm *QueryManager) GetByURL(urlPattern string, page, pageSize int) (*QueryResult, error)
GetByURL 根据URL查询日志(模糊匹配)
func (*QueryManager) GetErrors ¶
func (qm *QueryManager) GetErrors(page, pageSize int) (*QueryResult, error)
GetErrors 获取包含错误的日志
func (*QueryManager) GetFilterOptions ¶
func (qm *QueryManager) GetFilterOptions() map[string]interface{}
GetFilterOptions 获取可用的过滤选项
func (*QueryManager) GetInactiveStreamingRequests ¶ added in v0.13.5
func (qm *QueryManager) GetInactiveStreamingRequests(page, pageSize int) (*QueryResult, error)
GetInactiveStreamingRequests 获取非活跃的流式请求日志
func (*QueryManager) GetNonStreamingRequests ¶ added in v0.13.5
func (qm *QueryManager) GetNonStreamingRequests(page, pageSize int) (*QueryResult, error)
GetNonStreamingRequests 获取非流式请求日志
func (*QueryManager) GetRecent ¶
func (qm *QueryManager) GetRecent(limit int) ([]*LogEntry, error)
GetRecent 获取最近的日志条目 limit: 限制返回的条目数量
func (*QueryManager) GetSlowRequests ¶
func (qm *QueryManager) GetSlowRequests(threshold time.Duration, page, pageSize int) (*QueryResult, error)
GetSlowRequests 获取慢请求日志 threshold: 慢请求阈值
func (*QueryManager) GetStats ¶
func (qm *QueryManager) GetStats() (map[string]interface{}, error)
GetStats 获取统计信息
func (*QueryManager) GetStreamingRequests ¶ added in v0.13.5
func (qm *QueryManager) GetStreamingRequests(page, pageSize int) (*QueryResult, error)
GetStreamingRequests 获取流式请求日志
func (*QueryManager) Query ¶
func (qm *QueryManager) Query(options QueryOptions) (*QueryResult, error)
Query 执行查询 根据查询选项获取日志条目
func (*QueryManager) Search ¶
func (qm *QueryManager) Search(keyword string, page, pageSize int) (*QueryResult, error)
Search 执行搜索 根据关键词搜索日志内容
type QueryOptions ¶
type QueryOptions struct {
Page int `json:"page"` // 页码,从1开始
PageSize int `json:"page_size"` // 每页大小
Filters map[string]interface{} `json:"filters"` // 过滤条件
SortBy string `json:"sort_by"` // 排序字段
SortOrder string `json:"sort_order"` // 排序方向:asc/desc
}
QueryOptions 查询选项 定义查询的各种过滤条件和分页参数
type QueryResult ¶
type QueryResult struct {
Entries []*LogEntry `json:"entries"` // 日志条目列表
Total int `json:"total"` // 总记录数
Page int `json:"page"` // 当前页码
PageSize int `json:"page_size"` // 每页大小
TotalPages int `json:"total_pages"` // 总页数
}
QueryResult 查询结果 包含查询到的日志条目和分页信息
type Storage ¶
type Storage interface {
// Save 保存日志条目
Save(entry *LogEntry) error
// FindByID 根据ID查找日志条目
FindByID(id string) (*LogEntry, error)
// FindAll 查找所有日志条目,支持分页和过滤
FindAll(page, pageSize int, filters map[string]interface{}) ([]*LogEntry, int, error)
// Search 搜索日志内容
Search(keyword string, page, pageSize int) ([]*LogEntry, int, error)
// Cleanup 清理过期日志
Cleanup(before time.Time) error
// GetStats 获取统计信息
GetStats() (map[string]interface{}, error)
// GetMethods 获取HTTP方法统计
GetMethods() (map[string]int, error)
// GetStatusCodes 获取状态码统计
GetStatusCodes() (map[int]int, error)
// Close 关闭存储
Close() error
}
Storage 存储接口定义 支持多种存储方式:文件、内存、数据库