From 7edeff229ecf2fb71a395e154debc1c69c4510d5 Mon Sep 17 00:00:00 2001 From: DeFiDude <59237470+DeFiDude@users.noreply.github.com> Date: Tue, 10 Nov 2026 05:18:02 -0700 Subject: [PATCH] lxmd: take the log level from its own config and flags, as upstream does --- Cargo.lock | 28 +++++++++++++++++- Cargo.toml | 1 + crates/lxmf-tools/Cargo.toml | 2 +- crates/lxmf-tools/src/commands/lxmd.rs | 41 +++++++++++--------------- crates/lxmf-tools/src/lxmd_cli.rs | 3 +- 5 files changed, 47 insertions(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 355bb02..629c1bb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -686,6 +686,7 @@ dependencies = [ "rns-crypto", "rns-identity", "rns-runtime", + "rns-tools", "rns-transport", "rns-wire", "serde_json", @@ -693,7 +694,6 @@ dependencies = [ "thiserror 2.0.18", "tokio", "tracing", - "tracing-subscriber", "zeroize", ] @@ -1194,6 +1194,32 @@ dependencies = [ "zeroize", ] +[[package]] +name = "rns-tools" +version = "1.4.0" +dependencies = [ + "base64", + "bytes", + "clap", + "hex", + "nix 0.29.0", + "rmp-serde", + "rmpv", + "rns-crypto", + "rns-identity", + "rns-interface", + "rns-runtime", + "rns-transport", + "rns-wire", + "serde", + "serde_json", + "serialport", + "sha2", + "tokio", + "tracing", + "tracing-subscriber", +] + [[package]] name = "rns-transport" version = "1.4.0" diff --git a/Cargo.toml b/Cargo.toml index ea95edc..c2c6b8f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,6 +21,7 @@ rns-protocol = { path = "../rsReticulum/crates/rns-protocol", version = "~1.4.0" rns-transport = { path = "../rsReticulum/crates/rns-transport", version = "~1.4.0" } rns-runtime = { path = "../rsReticulum/crates/rns-runtime", version = "~1.4.0" } rns-interface = { path = "../rsReticulum/crates/rns-interface", version = "~1.4.0" } +rns-tools = { path = "../rsReticulum/crates/rns-tools", version = "~1.4.0" } # Workspace LXMF crates lxmf-core = { path = "crates/lxmf-core", version = "~1.4.0" } diff --git a/crates/lxmf-tools/Cargo.toml b/crates/lxmf-tools/Cargo.toml index 8184cee..c541095 100644 --- a/crates/lxmf-tools/Cargo.toml +++ b/crates/lxmf-tools/Cargo.toml @@ -15,11 +15,11 @@ rns-identity = { workspace = true } rns-transport = { workspace = true } rns-wire = { workspace = true } rns-crypto = { workspace = true } +rns-tools = { workspace = true } clap = { workspace = true } tokio = { workspace = true } bytes = { workspace = true } tracing = { workspace = true } -tracing-subscriber = { workspace = true } hex = { workspace = true } base64 = { workspace = true } serde_json = { workspace = true } diff --git a/crates/lxmf-tools/src/commands/lxmd.rs b/crates/lxmf-tools/src/commands/lxmd.rs index 6e00230..ac21adf 100644 --- a/crates/lxmf-tools/src/commands/lxmd.rs +++ b/crates/lxmf-tools/src/commands/lxmd.rs @@ -919,27 +919,21 @@ fn handle_pn_offer_request( } } -fn setup_logging(verbose: u8, quiet: u8, service: bool) { - let level = match (verbose, quiet) { - (v, _) if v >= 3 => tracing::Level::TRACE, - (2, _) => tracing::Level::DEBUG, - (1, _) => tracing::Level::INFO, - (0, 0) => { - if service { - tracing::Level::WARN - } else { - tracing::Level::INFO - } - } - (_, q) if q >= 2 => tracing::Level::ERROR, - (_, 1) => tracing::Level::WARN, - _ => tracing::Level::INFO, +/// Python `lxmd.program_setup`/`_remote_init`: the daemon starts from its own +/// config's `loglevel` (a missing file is the default config it writes first); +/// control commands never read it and start at Notice. +fn setup_logging(args: &Args, config_dir: &Path, rns_config_dir: &Path, control_command: bool) { + let configured = if control_command { + None + } else { + rns_runtime::config::Config::from_file(&config_dir.join("config")) + .or_else(|_| rns_runtime::config::Config::parse(example_config())) + .ok() + .and_then(|c| c.section("logging")?.get_int("loglevel")) }; - - tracing_subscriber::fmt() - .with_max_level(level) - .with_target(false) - .init(); + let level = rns_tools::Utility::Lxmd.loglevel(configured, args.verbose, args.quiet, false); + let timestamps = rns_tools::config_log_timestamps(rns_config_dir); + rns_tools::init_tracing(level, timestamps, true, std::io::stdout); } fn now_f64() -> f64 { @@ -5872,10 +5866,11 @@ pub(crate) async fn main() { return; } - setup_logging(args.verbose, args.quiet, args.service); - let (config_dir, rns_config_dir) = resolve_config_dirs(args.config.as_deref(), args.rnsconfig.as_deref()); + let is_control_command = + args.status || args.peers || args.sync.is_some() || args.unpeer.is_some(); + setup_logging(&args, &config_dir, &rns_config_dir, is_control_command); if args.migrate_propagation_store { let result = (|| -> std::io::Result<()> { @@ -5931,8 +5926,6 @@ pub(crate) async fn main() { return; } - let is_control_command = - args.status || args.peers || args.sync.is_some() || args.unpeer.is_some(); let control_preflight = if is_control_command { let peer_hash = if args.status || args.peers { None diff --git a/crates/lxmf-tools/src/lxmd_cli.rs b/crates/lxmf-tools/src/lxmd_cli.rs index 9ccabea..17ce8c4 100644 --- a/crates/lxmf-tools/src/lxmd_cli.rs +++ b/crates/lxmf-tools/src/lxmd_cli.rs @@ -79,8 +79,7 @@ pub struct Args { #[arg(long)] pub exampleconfig: bool, - /// Default to warning-level logging for service use; -v/-q override this. - /// The process remains in the foreground. + /// Service mode; the process remains in the foreground. #[arg(short = 's', long)] pub service: bool,