Skip to content

feat: add opt-in JSONL format for trace logs (Closes #8066)#8109

Open
Pleiades1726 wants to merge 3 commits into
AstrBotDevs:masterfrom
Pleiades1726:fix/trace-log-jsonl-format
Open

feat: add opt-in JSONL format for trace logs (Closes #8066)#8109
Pleiades1726 wants to merge 3 commits into
AstrBotDevs:masterfrom
Pleiades1726:fix/trace-log-jsonl-format

Conversation

@Pleiades1726
Copy link
Copy Markdown
Contributor

@Pleiades1726 Pleiades1726 commented May 9, 2026

背景

详见 Issue #8066。当前 trace 日志格式为带 [time] 前缀的格式,导致每行不是合法的 JSON,下游工具(jq、Python json.loads、ELK 等)无法直接解析。

改动

新增配置项 trace_log_format,支持两种模式:

说明 示例
prefixed(默认) 保持现有格式,向后兼容 [2026-05-07 13:45:12.123] {...}
jsonl 纯 JSON Lines,无前缀 {...}

修改文件

  • astrbot/core/config/default.py — 添加默认值 + metadata schema(两处)
  • astrbot/core/log.py_add_file_sink() 新增 trace_format 参数,configure_trace_logger() 读取配置并传递

使用方式

data/config.yaml 中设置:

trace_log_format: jsonl

重启后 trace 日志将输出纯 JSON Lines 格式。

Summary by Sourcery

Add a configurable format for trace log output, allowing opt-in JSON Lines in addition to the existing prefixed format.

New Features:

  • Introduce the trace_log_format configuration option to select between prefixed and JSONL trace log formats.

Enhancements:

  • Extend trace logger setup to honor the configured trace_log_format while preserving current behavior as the default.

@auto-assign auto-assign Bot requested review from Raven95676 and Soulter May 9, 2026 13:54
@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. area:core The bug / feature is about astrbot's core, backend labels May 9, 2026
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • When trace_log_format has an unexpected value, _add_file_sink silently falls back to the prefixed format; consider validating against the allowed options and either raising or logging a warning so misconfigurations are visible.
  • You now have the literal strings "prefixed" and "jsonl" in both the config schema and log.py; consider centralizing these as constants or an enum-like structure to avoid divergence if new formats are added later.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- When `trace_log_format` has an unexpected value, `_add_file_sink` silently falls back to the prefixed format; consider validating against the allowed options and either raising or logging a warning so misconfigurations are visible.
- You now have the literal strings "prefixed" and "jsonl" in both the config schema and `log.py`; consider centralizing these as constants or an enum-like structure to avoid divergence if new formats are added later.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new configuration option trace_log_format for trace logging, allowing users to choose between a timestamp-prefixed format and a raw jsonl format. The changes include updates to the default configuration, schema validation, and the logging utility to handle the format selection. I have no feedback to provide.

Seio added 2 commits May 9, 2026 22:02
Add a new config option 'trace_log_format' that supports two modes:
- 'prefixed' (default): [time] prefix format, backward compatible
- 'jsonl': pure JSON Lines format without prefix, each line is a
  valid JSON object parseable by jq, Python json.loads, ELK, etc.

This allows downstream tools and dashboards to ingest trace log
files directly without needing to regex-strip the timestamp prefix.

Closes AstrBotDevs#8066
@Pleiades1726 Pleiades1726 force-pushed the fix/trace-log-jsonl-format branch from fe7138c to 714cc34 Compare May 9, 2026 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core The bug / feature is about astrbot's core, backend size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant