1 unstable release
0.1.0 | Jul 18, 2022 |
---|
#14 in #verbose
22KB
605 lines
ndjsonloggercore
ndjsonloggercore is the library powering ndjsonlogger. It can be used as a stand-alone crate, althought it leads to verbose code without the macros provided in ndjsonlogger.
Example
[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}
Features
iso timestamp
To log an iso utc timestamp enable the isotimestamp feature.
NOTE: This implicity enables the std
feature as well.
[dependencies]
ndjosnloggercore = {version = "0.1", features = ["isotimestamp", "std"]}
{"level": "info", "ts": "2022-07-13T16:47:36.429838Z", "msg": "example message"}
Contributing
Contributions Welcome! Please open a github issue or pull request.
Dependencies
~38–345KB