【3FS】toml库

toml库

 

假设配置文件是 storage_main_app.toml

[common]

[common.log]

[[common.log.categories]]
categories = [ "." ]
handlers = [ "normal", "err", "fatal" ]
inherit = true
level = "INFO"
propagate = "NONE"

[[common.log.handlers]]
async = true
file_path = "/var/log/3fs/storage_main.log"
max_file_size = "100MB"
max_files = 10
name = "normal"
rotate = true
start_level = "NONE"
writer_type = "FILE"

[[common.log.handlers]]
async = false
file_path = "/var/log/3fs/storage_main-err.log"
max_file_size = "100MB"
max_files = 10
name = "err"
rotate = true
start_level = "ERR"
writer_type = "FILE"

结构上是这样:

root table
└── common                  table
    └── log                 table
        ├── categories      array
        │   └── [0]         table
        │       ├── categories  array
        │       ├── handlers    array
        │       └── level       string
        └── handlers        array
            ├── [0]         table
            └── [1]         table

 

 

TOML 写法 类型 C++ 读取
[common] table .as_table()
[common.log] table .as_table()
[[common.log.handlers]] array of tables .as_array()
categories = [ "." ] array .as_array()
name = "normal" string value .value_or("")
async = true bool value .value_or(false)
max_files = 10 integer value .value_or(0)
posted @ 2026-05-31 20:58  苏格拉底的落泪  阅读(7)  评论(0)    收藏  举报