1 个不稳定版本

0.1.0 2022年7月18日

#13#verbose

MIT 许可证

22KB
605

ndjsonloggercore

ndjsonloggercore 是驱动 ndjsonlogger 的库。它可以作为一个独立的 crate 使用,尽管没有 ndjsonlogger 中提供的宏,它会导致代码冗长。

示例

[dependencies]
ndjsonlogger = {version = "0.1", features = ["std"]}
use ndjsonloggercore::{log, level, Entry. Value, Atom, StdoutOutputter};

fn main() {
    // StdoutOutputter requires `std` crate feature.
    let mut outputter = StdoutOutputter::new();

    log(None, &mut outputter, "service started", level::Info, [].into_iter());

    let my_num: u64 = 15;
    let healthy = true;
    log(None, &mut outputter, "a log line", level::Error, [
        Entry{ key: "key1", value: Value::Atom(Atom::String("value1")) },
        Entry{ key: "key2", value: Value::Atom(Atom::Uint(my_num)) },
        Entry{ key: "healthy", value: Value::Atom(Atom::Bool(healthy)) },
    ]
    .into_iter(),
	);
}
{"level": "info", "msg": "service started"}
{"level": "error", "msg": "a log line", "key1": "value1", "key2": 15, "healthy": true}

功能

ISO 时间戳

要记录 ISO UTC 时间戳,请启用 isotimestamp 功能。

注意:这会隐式启用 std 功能。

[dependencies]
ndjosnloggercore = {version = "0.1", features = ["isotimestamp", "std"]}
{"level": "info", "ts": "2022-07-13T16:47:36.429838Z", "msg": "example message"}

贡献

欢迎贡献!请打开一个 github 问题或 pull request。

依赖

~38–345KB