Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions astrbot/core/config/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@
"trace_log_enable": False,
"trace_log_path": "logs/astrbot.trace.log",
"trace_log_max_mb": 20,
"trace_log_format": "prefixed",
"pip_install_arg": "",
"pypi_index_url": "https://mirrors.aliyun.com/pypi/simple/",
"persona": [], # deprecated
Expand Down Expand Up @@ -2960,6 +2961,11 @@
"type": "int",
"condition": {"trace_log_enable": True},
},
"trace_log_format": {
"type": "string",
"options": ["prefixed", "jsonl"],
"condition": {"trace_log_enable": True},
},
"t2i_strategy": {
"type": "string",
"options": ["remote", "local"],
Expand Down Expand Up @@ -4230,6 +4236,12 @@
"type": "int",
"hint": "超过大小后自动轮转,默认 20MB。",
},
"trace_log_format": {
"description": "Trace 日志格式",
"type": "string",
"options": ["prefixed", "jsonl"],
"hint": "\"prefixed\" 为带时间戳前缀的格式(默认);\"jsonl\" 为纯 JSON Lines 格式,每行一个 JSON 对象,便于被 jq 等工具解析。",
},
"pip_install_arg": {
"description": "pip 安装额外参数",
"type": "string",
Expand Down
9 changes: 8 additions & 1 deletion astrbot/core/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,17 +300,22 @@ def _add_file_sink(
max_mb: int | None,
backup_count: int,
trace: bool,
trace_format: str = "prefixed",
) -> int:
os.makedirs(os.path.dirname(file_path) or ".", exist_ok=True)
rotation = f"{max_mb} MB" if max_mb and max_mb > 0 else None
retention = (
backup_count if rotation and backup_count and backup_count > 0 else None
)
if trace:
if trace_format == "jsonl":
trace_format_str = "{message}"
else:
trace_format_str = "[{time:YYYY-MM-DD HH:mm:ss.SSS}] {message}"
return _loguru.add(
file_path,
level="INFO",
format="[{time:YYYY-MM-DD HH:mm:ss.SSS}] {message}",
format=trace_format_str,
encoding="utf-8",
rotation=rotation,
retention=retention,
Expand Down Expand Up @@ -391,6 +396,7 @@ def configure_trace_logger(cls, config: dict | None) -> None:
)
path = config.get("trace_log_path")
max_mb = config.get("trace_log_max_mb")
trace_format = config.get("trace_log_format", "prefixed")
if "log_file" in config:
legacy = config.get("log_file") or {}
path = path or legacy.get("trace_path")
Expand All @@ -414,4 +420,5 @@ def configure_trace_logger(cls, config: dict | None) -> None:
max_mb=max_mb,
backup_count=3,
trace=True,
trace_format=trace_format,
)
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,10 @@
"description": "Trace Log Max Size (MB)",
"hint": "Rotate when exceeding this size; default 20MB."
},
"trace_log_format": {
"description": "Trace Log Format",
"hint": "\"prefixed\" adds a timestamp prefix (default), suitable for human reading; \"jsonl\" outputs pure JSON Lines, one JSON object per line, for parsing by jq, Python json.loads, ELK, etc."
},
"pip_install_arg": {
"description": "Additional pip Installation Arguments",
"hint": "When installing plugin dependencies, Python's pip tool will be used. Additional arguments can be provided here, such as `--break-system-package`."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,10 @@
"description": "Макс. размер файла логов трассировки (МБ)",
"hint": "Ротация при достижении размера. По умолчанию 20МБ."
},
"trace_log_format": {
"description": "Формат логов трассировки",
"hint": "\"prefixed\" — с префиксом временной метки (по умолчанию), для чтения человеком; \"jsonl\" — чистый JSON Lines, один JSON-объект на строку, для анализа через jq, Python json.loads, ELK и т.д."
},
"pip_install_arg": {
"description": "Дополнительные аргументы установки pip",
"hint": "При установке зависимостей можно указать аргументы pip, напр. --break-system-package."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,10 @@
"description": "Trace 日志大小上限 (MB)",
"hint": "超过大小后自动轮转,默认 20MB。"
},
"trace_log_format": {
"description": "Trace 日志格式",
"hint": "\"prefixed\" 为带时间戳前缀的格式(默认),适用于人工阅读;\"jsonl\" 为纯 JSON Lines 格式,每行一个 JSON 对象,适用于被 jq、Python json.loads、ELK 等工具解析。"
},
"pip_install_arg": {
"description": "pip 安装额外参数",
"hint": "安装插件依赖时,会使用 Python 的 pip 工具。这里可以填写额外的参数,如 `--break-system-package` 等。"
Expand Down
Loading