ndjsonloggercore

Crates.iondjsonloggercore
lib.rsndjsonloggercore
version0.1.0
sourcesrc
created_at2022-07-18 09:30:28.950396
updated_at2022-07-18 09:30:28.950396
descriptionndjsonloggercore
homepagehttps://github.com/flickpp/ndjsonlogger
repositoryhttps://github.com/flickpp/ndjsonloggercore
max_upload_size
id627615
size21,174
(flickpp)

documentation

README

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.

Commit count: 9

cargo fmt