- 新增 gomsg/:帧协议(4B 大端长度 + UTF-8,64MiB 上限)、MsgClient/MsgServer、 RpcClient/RpcServer(_route 分发、错误脱敏、panic 恢复、json.Number 保精度)、 AsyncQueue[T]、LogClient(集中式日志,级别过滤 + fail-safe),线协议与 Python/C++ 字节级兼容 - waf/internal/logclient 改为 gomsg 薄适配层(336→20 行),main/engine/proxy 零改动 - gomsg 26 项单测全绿(-race);waf 编译通过
69 lines
1.7 KiB
Go
69 lines
1.7 KiB
Go
// Package logclient 基于 gomsg 的集中式日志客户端(异步批量推送 db2 Logs 表)。
|
|
//
|
|
// 原实现(pymsg 帧协议 + 异步队列)已抽取至 ../gomsg,本包保留包级 API
|
|
// 兼容层:main / engine / proxy 的调用点零改动。
|
|
package logclient
|
|
|
|
import "github.com/micro_servers/gomsg"
|
|
|
|
var (
|
|
lc *gomsg.LogClient
|
|
pendingLevel string
|
|
)
|
|
|
|
// Init 初始化全局日志客户端(读 LOG_DB_ADDR / LOG_LEVEL 环境变量)。
|
|
func Init() {
|
|
lc = gomsg.NewLogClient("")
|
|
if pendingLevel != "" {
|
|
lc.SetLevel(pendingLevel)
|
|
}
|
|
}
|
|
|
|
// SetLevel 设置最低日志级别(debug|info|warn|error,大小写不敏感)。
|
|
func SetLevel(level string) {
|
|
pendingLevel = level
|
|
if lc != nil {
|
|
lc.SetLevel(level)
|
|
}
|
|
}
|
|
|
|
// Push 推送一条日志(非阻塞,队列满或低于最低级别时静默丢弃)。
|
|
func Push(service, level, message string, extra map[string]any) {
|
|
if lc == nil {
|
|
return
|
|
}
|
|
lc.Push(gomsg.Entry{
|
|
Service: service,
|
|
Level: level,
|
|
Message: message,
|
|
Extra: extra,
|
|
})
|
|
}
|
|
|
|
// Debug 推送 DEBUG 级别日志。
|
|
func Debug(service, message string, extra map[string]any) {
|
|
Push(service, "DEBUG", message, extra)
|
|
}
|
|
|
|
// Info 推送 INFO 级别日志。
|
|
func Info(service, message string, extra map[string]any) {
|
|
Push(service, "INFO", message, extra)
|
|
}
|
|
|
|
// Warning 推送 WARNING 级别日志。
|
|
func Warning(service, message string, extra map[string]any) {
|
|
Push(service, "WARNING", message, extra)
|
|
}
|
|
|
|
// Error 推送 ERROR 级别日志。
|
|
func Error(service, message string, extra map[string]any) {
|
|
Push(service, "ERROR", message, extra)
|
|
}
|
|
|
|
// Flush 停止队列并 flush 剩余日志(用于进程退出前)。
|
|
func Flush() {
|
|
if lc != nil {
|
|
lc.Flush()
|
|
}
|
|
}
|