Skip to content

Commit 995f1ee

Browse files
committed
Update dependencies and example.
1 parent 54991ed commit 995f1ee

File tree

4 files changed

+23
-44
lines changed

4 files changed

+23
-44
lines changed

Cargo.toml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "structured-logger"
3-
version = "1.0.2"
3+
version = "1.0.3"
44
edition = "2018"
55
description = """
66
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.
@@ -26,13 +26,13 @@ default = ["log-panic"]
2626
log-panic = []
2727

2828
[dependencies]
29-
log = { version = "~0.4", features = [
29+
log = { version = "0.4", features = [
3030
"kv_unstable_serde",
3131
], default-features = false }
32-
parking_lot = { version = "~0.12", optional = false }
33-
serde = { version = "~1.0", features = ["derive"], default-features = false }
34-
serde_json = { version = "~1.0", features = ["std"], default-features = false }
35-
tokio = { version = "~1.29", features = [
32+
parking_lot = { version = "0.12", optional = false }
33+
serde = { version = "1.0", features = ["derive"], default-features = false }
34+
serde_json = { version = "1.0", features = ["std"], default-features = false }
35+
tokio = { version = "1.29", features = [
3636
"io-std",
3737
"io-util",
3838
"parking_lot",
@@ -41,5 +41,5 @@ tokio = { version = "~1.29", features = [
4141
], default-features = false }
4242

4343
[dev-dependencies]
44-
tokio = { version = "~1.29", features = ["full"] }
45-
gag = { version = "~1.0" }
44+
tokio = { version = "1.29", features = ["full"] }
45+
gag = { version = "1.0" }

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ See examples and the [API documentation] for more.
2020
Simple example:
2121
```rust
2222
use serde::Serialize;
23-
use structured_logger::{json::new_writer, unix_ms, Builder};
23+
use structured_logger::{async_json::new_writer, unix_ms, Builder};
2424

25-
fn main() {
25+
#[tokio::main]
26+
async fn main() {
2627
// Initialize the logger.
2728
Builder::with_level("info")
28-
.with_target_writer("*", new_writer(std::io::stdout()))
29+
.with_target_writer("*", new_writer(tokio::io::stdout()))
2930
.init();
3031

3132
let kv = ContextLog {

examples/simple.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
use serde::Serialize;
2-
use structured_logger::{json::new_writer, unix_ms, Builder};
2+
use structured_logger::{async_json::new_writer, unix_ms, Builder};
33

4-
fn main() {
4+
#[tokio::main]
5+
async fn main() {
56
// Initialize the logger.
67
Builder::with_level("info")
7-
.with_target_writer("*", new_writer(std::io::stdout()))
8+
.with_target_writer("*", new_writer(tokio::io::stdout()))
89
.init();
910

1011
let kv = ContextLog {

src/lib.rs

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,16 @@
3232
//! * Log panics example: <https://github.com/iorust/structured-logger/blob/main/examples/panic_log.rs>
3333
//! * Async log example: <https://github.com/iorust/structured-logger/blob/main/examples/async_log.rs>
3434
//!
35-
//! Muilti writers example:
35+
//! Simple example:
3636
//! ```rust
3737
//! use serde::Serialize;
38-
//! use std::{fs::File, io::stdout};
39-
//! use structured_logger::{json::new_writer, unix_ms, Builder};
38+
//! use structured_logger::{async_json::new_writer, unix_ms, Builder};
4039
//!
41-
//! fn main() {
40+
//! #[tokio::main]
41+
//! async fn main() {
4242
//! // Initialize the logger.
43-
//! // Optional: create a file to write logs to.
44-
//! let log_file = File::options()
45-
//! .create(true)
46-
//! .append(true)
47-
//! .open("app.log")
48-
//! .unwrap();
49-
//!
50-
//! // or Builder::with_level("debug")
51-
//! Builder::new()
52-
//! // Optional: set a specific writer (format to JSON, write to stdout) for target starts with "api".
53-
//! .with_target_writer("api*", new_writer(stdout()))
54-
//! // Optional: set a specific writer (format to JSON, write to app.log file) for target "file" and "db".
55-
//! .with_target_writer("file,db", new_writer(log_file))
43+
//! Builder::with_level("info")
44+
//! .with_target_writer("*", new_writer(tokio::io::stdout()))
5645
//! .init();
5746
//!
5847
//! let kv = ContextLog {
@@ -61,7 +50,7 @@
6150
//! };
6251
//!
6352
//! log::info!("hello world");
64-
//! // This log will be written to stderr (default writer):
53+
//! // This log will be written to stdout:
6554
//! // {"level":"INFO","message":"hello world","target":"simple","timestamp":1679745592127}
6655
//!
6756
//! log::info!(target: "api",
@@ -75,18 +64,6 @@
7564
//! );
7665
//! // This log will be written to stdout:
7766
//! // {"elapsed":10,"kv":{"uid":"user123","action":"upate_book"},"level":"INFO","message":"","method":"GET","path":"/hello","start":1679745592127,"status":200,"target":"api","timestamp":1679745592127}
78-
//!
79-
//! log::info!(target: "file",
80-
//! method = "GET",
81-
//! path = "/hello",
82-
//! status = 200_u16,
83-
//! start = unix_ms(),
84-
//! elapsed = 10_u64,
85-
//! kv = log::as_serde!(kv);
86-
//! "",
87-
//! );
88-
//! // This log will be written to file "app.log":
89-
//! // {"elapsed":10,"kv":{"uid":"user123","action":"upate_book"},"level":"INFO","message":"","method":"GET","path":"/hello","start":1679745592127,"status":200,"target":"file","timestamp":1679745592127}
9067
//! }
9168
//!
9269
//! #[derive(Serialize)]

0 commit comments

Comments
 (0)