From d78d21eeeb4d731448b957beb4555e5257a2ea1c Mon Sep 17 00:00:00 2001 From: Cole MacKenzie Date: Sun, 8 Oct 2023 10:15:01 -0700 Subject: [PATCH] docs: update readme.md and module docs --- README.md | 2 +- src/lib.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7449eae..8503820 100644 --- a/README.md +++ b/README.md @@ -45,4 +45,4 @@ See the [examples](./examples) directory for more examples. ## License -Licensed under MIT license ([LICENSE](LICENSE) or http://opensource.org/licenses/MIT) +Licensed under [MIT license](./LICENSE) diff --git a/src/lib.rs b/src/lib.rs index faf79eb..d43d146 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,45 @@ +//! # tracing-ndjson +//! +//! [![Rust](https://github.com/cmackenzie1/tracing-ndjson/actions/workflows/rust.yml/badge.svg)](https://github.com/cmackenzie1/tracing-ndjson/actions/workflows/rust.yml) +//! +//! A simple library for tracing in new-line delimited JSON format. This library is meant to be used with [tracing](https://github.com/tokio-rs/tracing) as an alternative to the `tracing_subscriber::fmt::json` formatter. +//! +//! ## Features +//! +//! - Configurable field names for `target`, `message`, `level`, and `timestamp`. +//! - Configurable timestamp formats such as RFC3339, UNIX timestamp, or any custom chrono format. +//! - Captures all span attributes and event fields in the root of the JSON object. +//! +//! ## Usage +//! +//! Add this to your `Cargo.toml`: +//! +//! ```toml +//! [dependencies] +//! tracing = "0.1" +//! tracing-ndjson = "0.1" +//! ``` +//! +//! ```rust +//! tracing_subscriber::registry() +//! .with(tracing_ndjson::builder().layer()) +//! .init(); +//! tracing::info!(life = 42, "Hello, world!"); +//! // {"level":"info","timestamp":"2023-10-08T03:30:52Z","target":"default","message":"Hello, world!"} +//! let span = tracing::info_span!("hello", "request.uri" = "https://example.com"); +//! span.in_scope(|| { +//! tracing::info!("Hello, world!"); +//! // {"level":"info","timestamp":"2023-10-08T03:34:33Z","target":"defaults","message":"Hello, world!","request.uri":"https://example.com"} +//! }); +//! ``` +//! +//! ### Examples +//! +//! See the [examples](./examples) directory for more examples. +//! +//! ## License +//! +//! Licensed under MIT license [LICENSE](./LICENSE) mod formatter; use tracing_core::Subscriber;