mirror of
https://github.com/nestriness/nestri.git
synced 2026-11-03 14:12:39 +02:00
fix(nescope): default log filter to info when RUST_LOG is unset
EnvFilter::from_default_env defaults to ERROR, so nescope's info and warn lines never reached the host journal. Fall back to info like neshub, nesinit and nesgamepad; align neswire, which had the same default.
This commit is contained in:
@@ -30,7 +30,7 @@
|
||||
//! | `PROTON_ENABLE_WAYLAND` | Set to `1` always, so Proton renders through Wayland |
|
||||
//! | `XCURSOR_THEME` | XCursor theme name for the software cursor |
|
||||
//! | `XCURSOR_SIZE` | XCursor size in pixels |
|
||||
//! | `RUST_LOG` | Tracing filter (e.g. `nescope=debug`) |
|
||||
//! | `RUST_LOG` | Tracing filter, default `info` (e.g. `nescope=debug`) |
|
||||
//!
|
||||
//! # Ctrl+C / shutdown
|
||||
//!
|
||||
@@ -193,9 +193,20 @@ struct Args {
|
||||
// Entry point
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/// Filter from `RUST_LOG`, or `info` when it is unset or unparsable.
|
||||
///
|
||||
/// `EnvFilter::from_default_env` alone defaults to ERROR, which hid every
|
||||
/// info/warn line from the host journal (nesinit only forwards `RUST_LOG` if
|
||||
/// it has it itself). Same fallback as neshub, nesinit and nesgamepad.
|
||||
fn log_filter(rust_log: Option<&str>) -> tracing_subscriber::EnvFilter {
|
||||
rust_log
|
||||
.and_then(|v| tracing_subscriber::EnvFilter::try_new(v).ok())
|
||||
.unwrap_or_else(|| "info".into())
|
||||
}
|
||||
|
||||
fn main() {
|
||||
tracing_subscriber::fmt()
|
||||
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
|
||||
.with_env_filter(log_filter(std::env::var("RUST_LOG").ok().as_deref()))
|
||||
.init();
|
||||
|
||||
let args = Args::parse();
|
||||
@@ -834,3 +845,38 @@ fn kill_all_children_sigkill() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod log_filter_tests {
|
||||
use super::log_filter;
|
||||
use tracing::Level;
|
||||
use tracing_subscriber::filter::LevelFilter;
|
||||
|
||||
#[test]
|
||||
fn unset_defaults_to_info_so_warn_is_visible() {
|
||||
let f = log_filter(None);
|
||||
assert_eq!(f.max_level_hint(), Some(LevelFilter::INFO));
|
||||
assert!(Level::WARN <= Level::INFO);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn debug_stays_out_of_the_default() {
|
||||
assert_ne!(log_filter(None).max_level_hint(), Some(LevelFilter::DEBUG));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn explicit_rust_log_wins() {
|
||||
assert_eq!(
|
||||
log_filter(Some("debug")).max_level_hint(),
|
||||
Some(LevelFilter::DEBUG)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn garbage_falls_back_to_info() {
|
||||
assert_eq!(
|
||||
log_filter(Some("=== not a filter ===")).max_level_hint(),
|
||||
Some(LevelFilter::INFO)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ struct Args {
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
tracing_subscriber::fmt()
|
||||
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
|
||||
.with_env_filter(tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| "info".into()))
|
||||
.init();
|
||||
|
||||
let args = Args::parse();
|
||||
|
||||
Reference in New Issue
Block a user