mirror of
https://github.com/deuxfleurs-org/garage.git
synced 2026-07-26 07:58:14 +00:00
fix: mark unsafety of std::env::set_var
and document the function.
This commit is contained in:
+6
-1
@@ -181,13 +181,18 @@ async fn run(opt: Opt) -> Result<(), Error> {
|
||||
}
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// should be called before tokio runtime initialization
|
||||
/// to limit multithread problem with `std::env::set_var` which is unsafe
|
||||
fn init_logging(opt: &Opt) {
|
||||
if std::env::var("RUST_LOG").is_err() {
|
||||
let default_log = match &opt.cmd {
|
||||
Command::Server => "netapp=info,garage=info",
|
||||
_ => "netapp=warn,garage=warn",
|
||||
};
|
||||
std::env::set_var("RUST_LOG", default_log)
|
||||
|
||||
unsafe { std::env::set_var("RUST_LOG", default_log) };
|
||||
}
|
||||
|
||||
let env_filter = tracing_subscriber::filter::EnvFilter::from_default_env();
|
||||
|
||||
@@ -388,9 +388,12 @@ impl Filter {
|
||||
}
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// initialize `RUST_LOG` env var before start tokio runtime to limit multithread problem with `std::env::set_var` which is unsafe
|
||||
fn main() -> Result<(), Error> {
|
||||
if std::env::var("RUST_LOG").is_err() {
|
||||
std::env::set_var("RUST_LOG", "warn")
|
||||
unsafe { std::env::set_var("RUST_LOG", "warn") };
|
||||
}
|
||||
|
||||
tracing_subscriber::fmt()
|
||||
|
||||
Reference in New Issue
Block a user