GFJsonLineLogSink¶
API Reference / Standard / 类索引
- 路径:
addons/gf/standard/utilities/logging/gf_json_line_log_sink.gd - 模块:
Standard - 继承:
GFLogSink - API:
public - 类别:运行时服务 (
runtime_service) - 首次版本:
3.17.0
把结构化日志条目写入 JSON Lines 文件。 该 sink 只负责把 GFLogUtility 传入的条目序列化为一行一个 JSON 对象, 不规定采集服务、上传时机或业务字段 schema。
成员概览¶
| 类型 | 名称 | 签名 |
|---|---|---|
| 枚举 | FileOpenMode |
enum FileOpenMode |
| 属性 | file_path |
var file_path: String = "" |
| 属性 | omit_formatted_text |
var omit_formatted_text: bool = false |
| 属性 | flush_interval_msec |
var flush_interval_msec: int = 250 |
| 属性 | flush_immediately |
var flush_immediately: bool = false |
| 属性 | max_jsonl_files |
var max_jsonl_files: int = 10: |
| 属性 | file_open_mode |
var file_open_mode: FileOpenMode = FileOpenMode.TRUNCATE |
| 方法 | get_report_redaction_profile |
func get_report_redaction_profile() -> String: |
| 方法 | init |
func init(owner: Object) -> void: |
| 方法 | write |
func write(entry: Dictionary) -> void: |
| 方法 | flush |
func flush() -> void: |
| 方法 | shutdown |
func shutdown() -> void: |
| 方法 | get_file_path |
func get_file_path() -> String: |
| 方法 | get_debug_snapshot |
func get_debug_snapshot() -> Dictionary: |
枚举¶
FileOpenMode¶
- API:
public - 首次版本:
8.0.0
enum FileOpenMode {
## 每次 init() 截断已有文件。
TRUNCATE,
## 每次 init() 追加到已有文件末尾。
APPEND,
## 目标文件已存在时拒绝打开。
FAIL_IF_EXISTS,
}
JSONL 文件打开策略。
属性¶
file_path¶
- API:
public
输出文件路径。留空时会根据 GFLogUtility 当前日志文件派生同名 .jsonl 文件。
omit_formatted_text¶
- API:
public
是否在写入前移除 text 字段,减少重复存储。
flush_interval_msec¶
- API:
public
文件自动 flush 间隔。设为 0 时每条日志都会立即 flush。
flush_immediately¶
- API:
public
是否强制每条 JSONL 日志立即 flush。
max_jsonl_files¶
- API:
public
使用默认派生路径时最多保留的 JSONL 文件数量。
file_open_mode¶
- API:
public - 首次版本:
8.0.0
自定义 file_path 重复初始化时的打开策略。
方法¶
get_report_redaction_profile¶
- API:
public - 首次版本:
8.0.0
使用本地 JSONL 诊断所需的 debug 脱敏 profile。
返回:debug profile 名称。
结构:
return: String naming GFReportValueCodec.REDACTION_PROFILE_DEBUG.
init¶
- API:
public
初始化 sink 并打开 JSONL 文件。
参数:
| 名称 | 说明 |
|---|---|
owner |
持有该 sink 的日志工具。 |
write¶
- API:
public
写入一条结构化日志。
参数:
| 名称 | 说明 |
|---|---|
entry |
日志条目字典。 |
结构:
entry: Dictionary log entry produced by GFLogUtility.
flush¶
- API:
public
刷新尚未写出的 JSONL 内容。
shutdown¶
- API:
public
关闭文件句柄。
get_file_path¶
- API:
public
获取当前实际输出路径。
返回:JSONL 文件路径。
get_debug_snapshot¶
- API:
public - 首次版本:
8.0.0
获取 JSONL sink 的调试快照。
返回:当前文件、打开状态和最近错误信息。
结构:
return: Dictionary,包含 file_path、is_open、last_error、last_error_message、write_error_count、cleanup_error_count 和 uses_default_file_path。