跳转至

GFBatchedLogSink

API Reference / Standard / 类索引

  • 路径:addons/gf/standard/utilities/logging/gf_batched_log_sink.gd
  • 模块:Standard
  • 继承:GFLogSink
  • API:public
  • 类别:运行时服务 (runtime_service)
  • 首次版本:3.17.0

结构化日志批量转发 sink。 该 sink 只负责清洗、缓冲和分批,把实际传输交给 sender_callback 或 batch_ready 信号。 它不绑定任何远端服务、HTTP 协议或业务字段。

成员概览

类型 名称 签名
信号 batch_ready signal batch_ready(batch: Array[Dictionary])
属性 batch_size var batch_size: int = 20:
属性 max_queue_size var max_queue_size: int = 500:
属性 flush_interval_msec var flush_interval_msec: int = 1000:
属性 omit_formatted_text var omit_formatted_text: bool = false
属性 metadata var metadata: Dictionary = {}
属性 sender_callback var sender_callback: Callable = Callable()
方法 init func init(_owner: Object) -> void:
方法 write func write(entry: Dictionary) -> void:
方法 flush func flush() -> void:
方法 shutdown func shutdown() -> void:
方法 get_pending_count func get_pending_count() -> int:
方法 get_dropped_count func get_dropped_count() -> int:
方法 get_debug_snapshot func get_debug_snapshot() -> Dictionary:

信号

batch_ready

  • API:public
signal batch_ready(batch: Array[Dictionary])

批次准备好时发出。

参数:

名称 说明
batch 日志批次数组。

结构:

  • batch: Array[Dictionary] of sanitized log entries.

属性

batch_size

  • API:public
var batch_size: int = 20:

每批最多包含的日志条数。

max_queue_size

  • API:public
var max_queue_size: int = 500:

队列最多保留的日志条数,超出时丢弃最旧条目。

flush_interval_msec

  • API:public
var flush_interval_msec: int = 1000:

自动 flush 间隔。设为 0 时只按 batch_size 或显式 flush。

omit_formatted_text

  • API:public
var omit_formatted_text: bool = false

是否在转发前移除 text 字段,减少重复载荷。

metadata

  • API:public
var metadata: Dictionary = {}

发送时附加到批次外层的元数据。

结构:

  • metadata: Dictionary[String, Variant] copied into each outgoing payload.

sender_callback

  • API:public
var sender_callback: Callable = Callable()

项目提供的发送回调,签名建议为 func(payload: Dictionary) -> Dictionary。

方法

init

  • API:public
func init(_owner: Object) -> void:

初始化 sink。

参数:

名称 说明
_owner 持有该 sink 的日志工具。

write

  • API:public
func write(entry: Dictionary) -> void:

写入一条结构化日志。

参数:

名称 说明
entry 日志条目字典。

结构:

  • entry: Dictionary log entry produced by GFLogUtility.

flush

  • API:public
func flush() -> void:

发送当前队列中的一批日志。

shutdown

  • API:public
func shutdown() -> void:

关闭 sink 并尽力 flush。

get_pending_count

  • API:public
func get_pending_count() -> int:

获取队列中的日志数量。

返回:待发送日志数量。

get_dropped_count

  • API:public
func get_dropped_count() -> int:

获取因队列上限丢弃的日志数量。

返回:丢弃数量。

get_debug_snapshot

  • API:public
func get_debug_snapshot() -> Dictionary:

获取调试快照。

返回:sink 状态字典。

结构:

  • return: Dictionary with pending_count, dropped_count, batch_size, max_queue_size, flush_interval_msec, and has_sender_callback.