日志
log 块用于配置 sing-box 的日志器:严重级别、输出位置、是否带 时间戳,以及是否完全禁用日志。
选项
| 字段 | 类型 | 默认值 | 允许值 | 描述 |
|---|---|---|---|---|
disabled | bool | false | true | false | 为 true 时 sing-box 安装空操作日志工厂,无论其他字段如何均不写出。 |
level | string | trace | trace | debug | info | warn | warning | error | fatal | panic | 最低严重级别。空字符串按默认处理;"warn" 与 "warning" 是等价别名。 |
output | string | (stderr) | <empty> | stderr | stdout | <file path> | 日志输出位置。空值默认 stderr;"stderr" 与 "stdout" 是字面量流名;其他取值视为文件路径。 |
timestamp | bool | false | true | false | 为 true 时每行前会带形如 "-0700 2006-01-02 15:04:05" 的时间戳;要在文件输出中看到时间戳必须开启。 |
源码: option/options.go:40-46 · 锚定版本 v1.13.11 (553cfa1)
示例
默认行为(配置中完全省略 log —— 等价于 {}):
json
{
"log": {}
}部署场景下让 sing-box 安静一点:
json
{
"log": {
"level": "warn",
"timestamp": true,
"output": "/var/log/sing-box.log"
}
}完全禁用日志:
json
{
"log": {
"disabled": true
}
}说明
level留空时的默认值是trace(最啰嗦的级别),而不是 info —— 见log/log.go:67-69。生产配置通常应显式设置level。output中"stderr"与"stdout"是字面量流名;其他非空值视为 文件路径(log/log.go:32-45)。- 写文件时颜色被强制关闭、时间戳被强制启用,与
timestamp设置 无关 —— 见格式化器配置log/log.go:46-52。
源码: option/options.go:40-46 · v1.13.11 (553cfa1)
