Skip to content

Commit

Permalink
Update dependencies and example.
Browse files Browse the repository at this point in the history
  • Loading branch information
zensh committed Aug 13, 2023
1 parent 54991ed commit 995f1ee
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 44 deletions.
16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "structured-logger"
version = "1.0.2"
version = "1.0.3"
edition = "2018"
description = """
A logging implementation for the log crate that logs structured values either synchronous or asynchronous, as JSON, CBOR, or any other format, into a file, stderr, stdout, or any other destination.
Expand All @@ -26,13 +26,13 @@ default = ["log-panic"]
log-panic = []

[dependencies]
log = { version = "~0.4", features = [
log = { version = "0.4", features = [
"kv_unstable_serde",
], default-features = false }
parking_lot = { version = "~0.12", optional = false }
serde = { version = "~1.0", features = ["derive"], default-features = false }
serde_json = { version = "~1.0", features = ["std"], default-features = false }
tokio = { version = "~1.29", features = [
parking_lot = { version = "0.12", optional = false }
serde = { version = "1.0", features = ["derive"], default-features = false }
serde_json = { version = "1.0", features = ["std"], default-features = false }
tokio = { version = "1.29", features = [
"io-std",
"io-util",
"parking_lot",
Expand All @@ -41,5 +41,5 @@ tokio = { version = "~1.29", features = [
], default-features = false }

[dev-dependencies]
tokio = { version = "~1.29", features = ["full"] }
gag = { version = "~1.0" }
tokio = { version = "1.29", features = ["full"] }
gag = { version = "1.0" }
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ See examples and the [API documentation] for more.
Simple example:
```rust
use serde::Serialize;
use structured_logger::{json::new_writer, unix_ms, Builder};
use structured_logger::{async_json::new_writer, unix_ms, Builder};

fn main() {
#[tokio::main]
async fn main() {
// Initialize the logger.
Builder::with_level("info")
.with_target_writer("*", new_writer(std::io::stdout()))
.with_target_writer("*", new_writer(tokio::io::stdout()))
.init();

let kv = ContextLog {
Expand Down
7 changes: 4 additions & 3 deletions examples/simple.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use serde::Serialize;
use structured_logger::{json::new_writer, unix_ms, Builder};
use structured_logger::{async_json::new_writer, unix_ms, Builder};

fn main() {
#[tokio::main]
async fn main() {
// Initialize the logger.
Builder::with_level("info")
.with_target_writer("*", new_writer(std::io::stdout()))
.with_target_writer("*", new_writer(tokio::io::stdout()))
.init();

let kv = ContextLog {
Expand Down
37 changes: 7 additions & 30 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,16 @@
//! * Log panics example: <https://github.com/iorust/structured-logger/blob/main/examples/panic_log.rs>
//! * Async log example: <https://github.com/iorust/structured-logger/blob/main/examples/async_log.rs>
//!
//! Muilti writers example:
//! Simple example:
//! ```rust
//! use serde::Serialize;
//! use std::{fs::File, io::stdout};
//! use structured_logger::{json::new_writer, unix_ms, Builder};
//! use structured_logger::{async_json::new_writer, unix_ms, Builder};
//!
//! fn main() {
//! #[tokio::main]
//! async fn main() {
//! // Initialize the logger.
//! // Optional: create a file to write logs to.
//! let log_file = File::options()
//! .create(true)
//! .append(true)
//! .open("app.log")
//! .unwrap();
//!
//! // or Builder::with_level("debug")
//! Builder::new()
//! // Optional: set a specific writer (format to JSON, write to stdout) for target starts with "api".
//! .with_target_writer("api*", new_writer(stdout()))
//! // Optional: set a specific writer (format to JSON, write to app.log file) for target "file" and "db".
//! .with_target_writer("file,db", new_writer(log_file))
//! Builder::with_level("info")
//! .with_target_writer("*", new_writer(tokio::io::stdout()))
//! .init();
//!
//! let kv = ContextLog {
Expand All @@ -61,7 +50,7 @@
//! };
//!
//! log::info!("hello world");
//! // This log will be written to stderr (default writer):
//! // This log will be written to stdout:
//! // {"level":"INFO","message":"hello world","target":"simple","timestamp":1679745592127}
//!
//! log::info!(target: "api",
Expand All @@ -75,18 +64,6 @@
//! );
//! // This log will be written to stdout:
//! // {"elapsed":10,"kv":{"uid":"user123","action":"upate_book"},"level":"INFO","message":"","method":"GET","path":"/hello","start":1679745592127,"status":200,"target":"api","timestamp":1679745592127}
//!
//! log::info!(target: "file",
//! method = "GET",
//! path = "/hello",
//! status = 200_u16,
//! start = unix_ms(),
//! elapsed = 10_u64,
//! kv = log::as_serde!(kv);
//! "",
//! );
//! // This log will be written to file "app.log":
//! // {"elapsed":10,"kv":{"uid":"user123","action":"upate_book"},"level":"INFO","message":"","method":"GET","path":"/hello","start":1679745592127,"status":200,"target":"file","timestamp":1679745592127}
//! }
//!
//! #[derive(Serialize)]
Expand Down

0 comments on commit 995f1ee

Please sign in to comment.