Skip to content

Commit 7d087c5

Browse files
committed
Docs: Document log limitations
1 parent e94f8f9 commit 7d087c5

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

docs/.python-version

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.10.13

docs/source/logging/logging.md

+68-1
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,71 @@ To start this example execute:
4545
RUST_LOG=info cargo run
4646
```
4747

48-
The full [example](https://github.com/scylladb/scylla-rust-driver/tree/main/examples/logging.rs) is available in the `examples` folder
48+
The full [example](https://github.com/scylladb/scylla-rust-driver/tree/main/examples/logging.rs) is available in the `examples` folder
49+
50+
## 'log' compatibility
51+
52+
It may be surprising for some that viewing drivers logs using `log` ecosystem doesn't work out of the box despite `tracing` having a compatiblity layer
53+
behind `log` / `log-always` feature flags.
54+
55+
The problem is that this compatibility using `log` feature (which is recommended for libraries) seems to not work well with `.with_current_subscriber()` / Tokio tasks.
56+
For example, for the following program:
57+
```rust
58+
# extern crate env_logger;
59+
# extern crate log;
60+
# extern crate tokio;
61+
# extern crate tracing;
62+
// main.rs
63+
64+
use tracing::instrument::WithSubscriber;
65+
66+
#[tokio::main]
67+
async fn main() {
68+
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
69+
70+
log::info!("info log");
71+
tracing::info!("info tracing");
72+
73+
tokio::spawn(
74+
async move {
75+
log::info!("spawned info log");
76+
tracing::info!("spawned info tracing")
77+
}
78+
.with_current_subscriber(),
79+
)
80+
.await
81+
.unwrap();
82+
83+
log::info!("another info log");
84+
tracing::info!("another info tracing");
85+
}
86+
87+
```
88+
89+
```toml
90+
# Cargo.toml
91+
92+
[package]
93+
name = "reproducer"
94+
version = "1.0.0"
95+
edition = "2021"
96+
97+
[dependencies]
98+
env_logger = "0.10"
99+
log = "0.4"
100+
tracing = { version = "0.1.36", features = [ "log" ] }
101+
tokio = { version = "1.27", features = [ "full" ] }
102+
```
103+
104+
the output is:
105+
```
106+
[2024-01-26T00:51:06Z INFO reproducer] info log
107+
[2024-01-26T00:51:06Z INFO reproducer] info tracing
108+
[2024-01-26T00:51:06Z INFO reproducer] spawned info log
109+
[2024-01-26T00:51:06Z INFO reproducer] another info log
110+
```
111+
112+
The other feature, `log-always`, works with the driver - but is not something we want to enable in this library.
113+
We recommend using tracing ecosystem, but if for some reason you need to stick with `log`, you can try
114+
enabling `log-always` feature in `tracing` by adding it to your direct dependencies (`tracing = { version = "0.1", features = [ "log-always" ] }`).
115+
This should enable driver log collection via `log` loggers.

0 commit comments

Comments
 (0)