Crates.io | ndjsonloggercore |
lib.rs | ndjsonloggercore |
version | 0.1.0 |
source | src |
created_at | 2022-07-18 09:30:28.950396 |
updated_at | 2022-07-18 09:30:28.950396 |
description | ndjsonloggercore |
homepage | https://github.com/flickpp/ndjsonlogger |
repository | https://github.com/flickpp/ndjsonloggercore |
max_upload_size | |
id | 627615 |
size | 21,174 |
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.
[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}
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"}
Contributions Welcome! Please open a github issue or pull request.