Env logger feature (#3775)
* feat: Expose and configure tracing env-filter * doc: Add env-filter doc part * chore: Remove conditional import * Move logger env-filter feature out of feature flag * Update logger env filtering * Add RUST_LOG to the process from the cli * Typo * fix clippy * clippy
This commit is contained in:
1 parent
9ffa42392f
commit
93a557c322
4 files changed
+17
-4
No files matched your search
@@ -2,6 +2,7 @@ use crate::{AppBundle, DioxusCrate, Platform, Result};
|
||||
use anyhow::Context;
|
||||
use dioxus_cli_opt::process_file_to;
|
||||
use std::{
|
||||
env,
|
||||
net::SocketAddr,
|
||||
path::{Path, PathBuf},
|
||||
process::Stdio,
|
||||
@@ -112,6 +113,10 @@ impl AppHandle {
|
||||
envs.push((dioxus_cli_config::ASSET_ROOT_ENV, base_path.clone()));
|
||||
}
|
||||
|
||||
if let Some(env_filter) = env::var_os("RUST_LOG").and_then(|e| e.into_string().ok()) {
|
||||
envs.push(("RUST_LOG", env_filter));
|
||||
}
|
||||
|
||||
// Launch the server if we were given an address to start it on, and the build includes a server. After we
|
||||
// start the server, consume its stdout/stderr.
|
||||
if let (Some(addr), Some(server)) = (start_fullstack_on_address, self.server_exe()) {
|
||||
|
||||
@@ -15,7 +15,10 @@ categories = ["development-tools::debugging"]
|
||||
[dependencies]
|
||||
dioxus-cli-config = { workspace = true }
|
||||
tracing = { workspace = true }
|
||||
tracing-subscriber = { workspace = true, features = ["registry", "std"] }
|
||||
tracing-subscriber = { workspace = true, features = ["registry", "std", "env-filter"] }
|
||||
|
||||
[features]
|
||||
default = []
|
||||
|
||||
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
||||
tracing-wasm = { workspace = true }
|
||||
|
||||
@@ -64,9 +64,8 @@ fn App() -> Element {
|
||||
p { "hi" }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
```
|
||||
For non-wasm targets, runtime filtering is based on the `RUST_LOG` environment variable. e.g. for `RUST_LOG=none,crateName=trace` only logs trace and above for `crateName` will be captured. See [here](https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives) for syntax. For crates with `-` in the name, these need to be changed to `_` in `RUST_LOG`.
|
||||
|
||||
## Platform Support
|
||||
Dioxus logger will eventually support every target that Dioxus does. Currently mobile and TUI are not supported.
|
||||
|
||||
@@ -97,7 +97,13 @@ pub fn init(level: Level) -> Result<(), SetGlobalDefaultError> {
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
{
|
||||
let sub = tracing_subscriber::FmtSubscriber::builder().with_max_level(level);
|
||||
let sub = tracing_subscriber::FmtSubscriber::builder()
|
||||
.with_max_level(level)
|
||||
.with_env_filter(
|
||||
tracing_subscriber::EnvFilter::builder()
|
||||
.with_default_directive(level.into())
|
||||
.from_env_lossy(),
|
||||
);
|
||||
|
||||
if !dioxus_cli_config::is_cli_enabled() {
|
||||
return set_global_default(sub.finish());
|
||||
|
||||
Reference in new issue
Block a user