https://github.com/flickpp/ndjsonloggercore
https://github.com/flickpp/ndjsonloggercore
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/flickpp/ndjsonloggercore
- Owner: flickpp
- Created: 2022-07-13T15:55:08.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2022-09-30T16:35:27.000Z (over 3 years ago)
- Last Synced: 2025-02-28T08:05:54.110Z (over 1 year ago)
- Language: Rust
- Size: 22.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ndjsonloggercore
ndjsonloggercore is the library powering
[ndjsonlogger](https://github.com/flickpp/ndjsonlogger).
It can be used as a stand-alone crate, althought it leads to verbose code without
the macros provided in ndjsonlogger.
## Example
```toml
[dependencies]
ndjsonlogger = {version = "0.1", features = ["std"]}
```
```rust
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(),
);
}
```
```json
{"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.
```toml
[dependencies]
ndjosnloggercore = {version = "0.1", features = ["isotimestamp", "std"]}
```
```json
{"level": "info", "ts": "2022-07-13T16:47:36.429838Z", "msg": "example message"}
```
## Contributing
Contributions Welcome! Please open a github issue or pull request.