diff options
| author | Linus Färnstrand <faern@faern.net> | 2022-01-07 13:36:45 +0100 |
|---|---|---|
| committer | Linus Färnstrand <faern@faern.net> | 2022-01-07 16:13:27 +0100 |
| commit | 7d49bb584d89cce115133fe0a2ce709ae985c3fc (patch) | |
| tree | 6c5b3805ce9796f4cfeb5b87ba5e0d3f2cff5706 /mullvad-daemon/src | |
| parent | 927c614b79b21be0766f61239eb8c5d578cf4f55 (diff) | |
| download | mullvadvpn-7d49bb584d89cce115133fe0a2ce709ae985c3fc.tar.xz mullvadvpn-7d49bb584d89cce115133fe0a2ce709ae985c3fc.zip | |
Always use logging macros prefixed with log::
Diffstat (limited to 'mullvad-daemon/src')
| -rw-r--r-- | mullvad-daemon/src/cli.rs | 1 | ||||
| -rw-r--r-- | mullvad-daemon/src/lib.rs | 75 | ||||
| -rw-r--r-- | mullvad-daemon/src/logging.rs | 1 | ||||
| -rw-r--r-- | mullvad-daemon/src/main.rs | 15 | ||||
| -rw-r--r-- | mullvad-daemon/src/relays.rs | 30 |
5 files changed, 60 insertions, 62 deletions
diff --git a/mullvad-daemon/src/cli.rs b/mullvad-daemon/src/cli.rs index 95e466c65e..f3b1436187 100644 --- a/mullvad-daemon/src/cli.rs +++ b/mullvad-daemon/src/cli.rs @@ -1,5 +1,4 @@ use clap::{crate_authors, crate_description, crate_name, App, Arg}; -use log; use crate::version; diff --git a/mullvad-daemon/src/lib.rs b/mullvad-daemon/src/lib.rs index 58fa2469d4..dbf1b26025 100644 --- a/mullvad-daemon/src/lib.rs +++ b/mullvad-daemon/src/lib.rs @@ -29,7 +29,6 @@ use futures::{ future::{abortable, AbortHandle, Future}, StreamExt, }; -use log::{debug, error, info, warn}; use mullvad_rpc::availability::ApiAvailabilityHandle; use mullvad_types::{ account::{AccountData, AccountToken, VoucherSubmission}, @@ -602,7 +601,7 @@ where .map_err(Error::ReadCachedTargetState), Err(e) => { if e.kind() == io::ErrorKind::NotFound { - debug!("No cached target state to load"); + log::debug!("No cached target state to load"); Ok(None) } else { Err(Error::OpenCachedTargetState(e)) @@ -610,11 +609,11 @@ where } } .unwrap_or_else(|error| { - error!("{}", error.display_chain()); + log::error!("{}", error.display_chain()); Some(TargetState::Secured) }); if let Some(cached_target_state) = &cached_target_state { - info!( + log::info!( "Loaded cached target state \"{}\" from {}", cached_target_state, target_cache.display() @@ -628,7 +627,7 @@ where let initial_target_state = if settings.get_account_token().is_some() { if settings.auto_connect { // Note: Auto-connect overrides the cached target state - info!("Automatically connecting since auto-connect is turned on"); + log::info!("Automatically connecting since auto-connect is turned on"); TargetState::Secured } else { cached_target_state.unwrap_or(TargetState::Unsecured) @@ -901,7 +900,7 @@ where if !lock_target_cache { let target_cache = cache_dir.join(TARGET_START_STATE_FILE); let _ = fs::remove_file(target_cache).await.map_err(|e| { - error!("Cannot delete target tunnel state cache: {}", e); + log::error!("Cannot delete target tunnel state cache: {}", e); }); } } @@ -985,17 +984,17 @@ where self.unschedule_reconnect(); - debug!("New tunnel state: {:?}", tunnel_state); + log::debug!("New tunnel state: {:?}", tunnel_state); match tunnel_state { TunnelState::Disconnected => self.state.disconnected(), TunnelState::Error(ref error_state) => { if error_state.is_blocking() { - info!( + log::info!( "Blocking all network connections, reason: {}", error_state.cause() ); } else { - error!( + log::error!( "FAILED TO BLOCK NETWORK CONNECTIONS, ENTERED ERROR STATE BECAUSE: {}", error_state.cause() ); @@ -1093,7 +1092,7 @@ where log::error!("Failed to send tunnel parameters"); } } else { - error!("No account token configured"); + log::error!("No account token configured"); } } @@ -1440,7 +1439,7 @@ where let state_change_initated = self.set_target_state(new_target_state).await; Self::oneshot_send(tx, state_change_initated, "state change initiated"); } else { - warn!("Ignoring target state change request due to shutdown"); + log::warn!("Ignoring target state change request due to shutdown"); } } @@ -1449,7 +1448,7 @@ where self.connect_tunnel(); Self::oneshot_send(tx, true, "reconnect issued"); } else { - debug!("Ignoring reconnect command. Currently not in secured state"); + log::debug!("Ignoring reconnect command. Currently not in secured state"); Self::oneshot_send(tx, false, "reconnect issued"); } } @@ -1503,7 +1502,7 @@ where geoip::send_location_request(rpc_service) .await .map_err(|e| { - warn!("Unable to fetch GeoIP location: {}", e.display_chain()); + log::warn!("Unable to fetch GeoIP location: {}", e.display_chain()); }) } } @@ -1626,11 +1625,13 @@ where if account_changed { match account_token { Some(_) => { - info!("Initiating tunnel restart because the account token changed"); + log::info!( + "Initiating tunnel restart because the account token changed" + ); self.reconnect_tunnel(); } None => { - info!("Disconnecting because account token was cleared"); + log::info!("Disconnecting because account token was cleared"); self.set_target_state(TargetState::Unsecured).await; } }; @@ -1840,7 +1841,7 @@ where #[cfg(target_os = "linux")] fn on_get_split_tunnel_processes(&mut self, tx: ResponseTx<Vec<i32>, split_tunnel::Error>) { let result = self.exclude_pids.list().map_err(|error| { - error!("{}", error.display_chain_with_msg("Unable to obtain PIDs")); + log::error!("{}", error.display_chain_with_msg("Unable to obtain PIDs")); error }); Self::oneshot_send(tx, result, "get_split_tunnel_processes response"); @@ -1849,7 +1850,7 @@ where #[cfg(target_os = "linux")] fn on_add_split_tunnel_process(&mut self, tx: ResponseTx<(), split_tunnel::Error>, pid: i32) { let result = self.exclude_pids.add(pid).map_err(|error| { - error!("{}", error.display_chain_with_msg("Unable to add PID")); + log::error!("{}", error.display_chain_with_msg("Unable to add PID")); error }); Self::oneshot_send(tx, result, "add_split_tunnel_process response"); @@ -1862,7 +1863,7 @@ where pid: i32, ) { let result = self.exclude_pids.remove(pid).map_err(|error| { - error!("{}", error.display_chain_with_msg("Unable to remove PID")); + log::error!("{}", error.display_chain_with_msg("Unable to remove PID")); error }); Self::oneshot_send(tx, result, "remove_split_tunnel_process response"); @@ -1871,7 +1872,7 @@ where #[cfg(target_os = "linux")] fn on_clear_split_tunnel_processes(&mut self, tx: ResponseTx<(), split_tunnel::Error>) { let result = self.exclude_pids.clear().map_err(|error| { - error!("{}", error.display_chain_with_msg("Unable to clear PIDs")); + log::error!("{}", error.display_chain_with_msg("Unable to clear PIDs")); error }); Self::oneshot_send(tx, result, "clear_split_tunnel_processes response"); @@ -2015,13 +2016,13 @@ where self.event_listener .notify_settings(self.settings.to_settings()); if let Some(TunnelType::Wireguard) = self.get_connected_tunnel_type() { - info!("Initiating tunnel restart"); + log::info!("Initiating tunnel restart"); self.reconnect_tunnel(); } } } Err(error) => { - error!( + log::error!( "{}", error.display_chain_with_msg("Unable to save settings") ); @@ -2042,12 +2043,12 @@ where if settings_changed { self.event_listener .notify_settings(self.settings.to_settings()); - info!("Initiating tunnel restart because the relay settings changed"); + log::info!("Initiating tunnel restart because the relay settings changed"); self.reconnect_tunnel(); } } Err(e) => { - error!("{}", e.display_chain_with_msg("Unable to save settings")); + log::error!("{}", e.display_chain_with_msg("Unable to save settings")); Self::oneshot_send(tx, Err(e), "update_relay_settings response"); } } @@ -2065,7 +2066,7 @@ where } } Err(e) => { - error!("{}", e.display_chain_with_msg("Unable to save settings")); + log::error!("{}", e.display_chain_with_msg("Unable to save settings")); Self::oneshot_send(tx, Err(e), "set_allow_lan response"); } } @@ -2088,7 +2089,7 @@ where } } Err(e) => { - error!("{}", e.display_chain_with_msg("Unable to save settings")); + log::error!("{}", e.display_chain_with_msg("Unable to save settings")); Self::oneshot_send(tx, Err(e), "set_show_beta_releases response"); } } @@ -2115,7 +2116,7 @@ where } } Err(e) => { - error!("{}", e.display_chain_with_msg("Unable to save settings")); + log::error!("{}", e.display_chain_with_msg("Unable to save settings")); Self::oneshot_send(tx, Err(e), "set_block_when_disconnected response"); } } @@ -2136,7 +2137,7 @@ where } } Err(e) => { - error!("{}", e.display_chain_with_msg("Unable to save settings")); + log::error!("{}", e.display_chain_with_msg("Unable to save settings")); Self::oneshot_send(tx, Err(e), "set auto-connect response"); } } @@ -2155,7 +2156,7 @@ where self.event_listener .notify_settings(self.settings.to_settings()); if let Some(TunnelType::OpenVpn) = self.get_connected_tunnel_type() { - info!( + log::info!( "Initiating tunnel restart because the OpenVPN mssfix setting changed" ); self.reconnect_tunnel(); @@ -2163,7 +2164,7 @@ where } } Err(e) => { - error!("{}", e.display_chain_with_msg("Unable to save settings")); + log::error!("{}", e.display_chain_with_msg("Unable to save settings")); Self::oneshot_send(tx, Err(e), "set_openvpn_mssfix response"); } } @@ -2228,12 +2229,12 @@ where if settings_changed { self.event_listener .notify_settings(self.settings.to_settings()); - info!("Initiating tunnel restart because the enable IPv6 setting changed"); + log::info!("Initiating tunnel restart because the enable IPv6 setting changed"); self.reconnect_tunnel(); } } Err(e) => { - error!("{}", e.display_chain_with_msg("Unable to save settings")); + log::error!("{}", e.display_chain_with_msg("Unable to save settings")); Self::oneshot_send(tx, Err(e), "set_enable_ipv6 response"); } } @@ -2256,7 +2257,7 @@ where } } Err(e) => { - error!("{}", e.display_chain_with_msg("Unable to save settings")); + log::error!("{}", e.display_chain_with_msg("Unable to save settings")); Self::oneshot_send(tx, Err(e), "set_dns_options response"); } } @@ -2319,7 +2320,7 @@ where self.event_listener .notify_settings(self.settings.to_settings()); if let Some(TunnelType::Wireguard) = self.get_connected_tunnel_type() { - info!( + log::info!( "Initiating tunnel restart because the WireGuard MTU setting changed" ); self.reconnect_tunnel(); @@ -2327,7 +2328,7 @@ where } } Err(e) => { - error!("{}", e.display_chain_with_msg("Unable to save settings")); + log::error!("{}", e.display_chain_with_msg("Unable to save settings")); Self::oneshot_send(tx, Err(e), "set_wireguard_mtu response"); } } @@ -2352,7 +2353,7 @@ where } } Err(e) => { - error!("{}", e.display_chain_with_msg("Unable to save settings")); + log::error!("{}", e.display_chain_with_msg("Unable to save settings")); Self::oneshot_send(tx, Err(e), "set_wireguard_rotation_interval response"); } } @@ -2486,7 +2487,7 @@ where fn oneshot_send<T>(tx: oneshot::Sender<T>, t: T, msg: &'static str) { if tx.send(t).is_err() { - warn!("Unable to send {} to the daemon command sender", msg); + log::warn!("Unable to send {} to the daemon command sender", msg); } } @@ -2555,7 +2556,7 @@ where /// Returns a bool representing whether or not a state change was initiated. async fn set_target_state(&mut self, new_state: TargetState) -> bool { if new_state != self.target_state || self.tunnel_state.is_in_error_state() { - debug!("Target state {:?} => {:?}", self.target_state, new_state); + log::debug!("Target state {:?} => {:?}", self.target_state, new_state); if new_state != self.target_state { self.target_state = new_state; diff --git a/mullvad-daemon/src/logging.rs b/mullvad-daemon/src/logging.rs index 6c5aeb98d6..5eca9b638f 100644 --- a/mullvad-daemon/src/logging.rs +++ b/mullvad-daemon/src/logging.rs @@ -2,7 +2,6 @@ use fern::{ colors::{Color, ColoredLevelConfig}, Output, }; -use log; use std::{fmt, io, path::PathBuf}; use talpid_core::logging::rotate_log; diff --git a/mullvad-daemon/src/main.rs b/mullvad-daemon/src/main.rs index b438e112cc..f11bb30d98 100644 --- a/mullvad-daemon/src/main.rs +++ b/mullvad-daemon/src/main.rs @@ -1,6 +1,5 @@ #![deny(rust_2018_idioms)] -use log::{debug, error, info, trace, warn}; use mullvad_daemon::{ logging, management_interface::{ManagementInterfaceEventBroadcaster, ManagementInterfaceServer}, @@ -26,7 +25,7 @@ fn main() { std::process::exit(1) }); - trace!("Using configuration: {:?}", config); + log::trace!("Using configuration: {:?}", config); let runtime = new_runtime_builder().build().unwrap_or_else(|error| { eprintln!("{}", error.display_chain()); @@ -36,11 +35,11 @@ fn main() { let exit_code = match runtime.block_on(run_platform(config, log_dir)) { Ok(_) => 0, Err(error) => { - error!("{}", error); + log::error!("{}", error); 1 } }; - debug!("Process exiting with code {}", exit_code); + log::debug!("Process exiting with code {}", exit_code); std::process::exit(exit_code); } @@ -58,7 +57,7 @@ fn init_logging(config: &cli::Config) -> Result<Option<PathBuf>, String> { exception_logging::enable(); version::log_version(); if let Some(ref log_dir) = log_dir { - info!("Logging to {}", log_dir.display()); + log::info!("Logging to {}", log_dir.display()); } Ok(log_dir) } @@ -114,7 +113,7 @@ async fn run_standalone(log_dir: Option<PathBuf>) -> Result<(), String> { } if !running_as_admin() { - warn!("Running daemon as a non-administrator user, clients might refuse to connect"); + log::warn!("Running daemon as a non-administrator user, clients might refuse to connect"); } let daemon = create_daemon(log_dir).await?; @@ -125,7 +124,7 @@ async fn run_standalone(log_dir: Option<PathBuf>) -> Result<(), String> { daemon.run().await.map_err(|e| e.display_chain())?; - info!("Mullvad daemon is quitting"); + log::info!("Mullvad daemon is quitting"); thread::sleep(Duration::from_millis(500)); Ok(()) } @@ -163,7 +162,7 @@ async fn spawn_management_interface( error.display_chain_with_msg("Unable to start management interface server") })?; - info!("Management interface listening on {}", socket_path); + log::info!("Management interface listening on {}", socket_path); Ok(event_broadcaster) } diff --git a/mullvad-daemon/src/relays.rs b/mullvad-daemon/src/relays.rs index 332baf5a85..89b14f08aa 100644 --- a/mullvad-daemon/src/relays.rs +++ b/mullvad-daemon/src/relays.rs @@ -8,7 +8,6 @@ use futures::{ FutureExt, SinkExt, StreamExt, }; use ipnetwork::IpNetwork; -use log::{debug, error, info, warn}; use mullvad_rpc::{availability::ApiAvailabilityHandle, rest::MullvadRestHandle, RelayListProxy}; use mullvad_types::{ endpoint::MullvadEndpoint, @@ -141,7 +140,7 @@ impl ParsedRelays { } pub fn from_file(path: impl AsRef<Path>) -> Result<Self, Error> { - debug!("Reading relays from {}", path.as_ref().display()); + log::debug!("Reading relays from {}", path.as_ref().display()); let (last_modified, file) = Self::open_file(path.as_ref()).map_err(Error::OpenRelayCache)?; let relay_list = @@ -193,13 +192,13 @@ impl RelaySelector { let resource_path = resource_dir.join(RELAYS_FILENAME); let unsynchronized_parsed_relays = Self::read_relays_from_disk(&cache_path, &resource_path) .unwrap_or_else(|error| { - error!( + log::error!( "{}", error.display_chain_with_msg("Unable to load cached relays") ); ParsedRelays::empty() }); - info!( + log::info!( "Initialized with {} cached relays from {}", unsynchronized_parsed_relays.relays().len(), DateTime::<Local>::from(unsynchronized_parsed_relays.last_updated()) @@ -296,9 +295,10 @@ impl RelaySelector { if let Some((entry_relay, mut entry_endpoint)) = entry_endpoint.take() { self.set_entry_peers(peer, &mut entry_endpoint); let addr_in = entry_endpoint.to_endpoint().address.ip(); - info!( + log::info!( "Selected entry relay {} at {}", - entry_relay.hostname, addr_in + entry_relay.hostname, + addr_in ); return Ok((exit_relay, Some(entry_relay), entry_endpoint)); } else if relay_constraints.wireguard_constraints.use_multihop { @@ -326,7 +326,7 @@ impl RelaySelector { if let Some((relay, endpoint)) = self.get_tunnel_endpoint_internal(&preferred_constraints, wg_entry_peer) { - debug!( + log::debug!( "Relay matched on highest preference for retry attempt {}", retry_attempt ); @@ -334,13 +334,13 @@ impl RelaySelector { } else if let Some((relay, endpoint)) = self.get_tunnel_endpoint_internal(&relay_constraints, wg_entry_peer) { - debug!( + log::debug!( "Relay matched on second preference for retry attempt {}", retry_attempt ); Ok((relay, endpoint)) } else { - warn!("No relays matching {}", &relay_constraints); + log::warn!("No relays matching {}", &relay_constraints); Err(Error::NoRelay) } } @@ -636,7 +636,7 @@ impl RelaySelector { .as_ref() .map(|endpoint| endpoint.to_endpoint().address.ip()) .unwrap_or(IpAddr::from(selected_relay.ipv4_addr_in)); - info!("Selected relay {} at {}", selected_relay.hostname, addr_in); + log::info!("Selected relay {} at {}", selected_relay.hostname, addr_in); endpoint.map(|endpoint| (selected_relay.clone(), endpoint)) }) } @@ -801,7 +801,7 @@ impl RelaySelector { .shadowsocks .choose(&mut self.rng) .map(|shadowsocks_endpoint| { - info!( + log::info!( "Selected Shadowsocks bridge {} at {}:{}/{}", relay.hostname, relay.ipv4_addr_in, @@ -924,7 +924,7 @@ impl RelaySelector { } port_index -= ports_in_range; } - error!("Port selection algorithm is broken!"); + log::error!("Port selection algorithm is broken!"); None } Constraint::Only(port) => { @@ -1120,14 +1120,14 @@ impl RelayListUpdater { async fn update_cache(&mut self, new_relay_list: RelayList) -> Result<(), Error> { if let Err(error) = Self::cache_relays(&self.cache_path, &new_relay_list).await { - error!( + log::error!( "{}", error.display_chain_with_msg("Failed to update relay cache on disk") ); } let new_parsed_relays = ParsedRelays::from_relay_list(new_relay_list, SystemTime::now()); - info!( + log::info!( "Downloaded relay inventory has {} relays", new_parsed_relays.relays().len() ); @@ -1140,7 +1140,7 @@ impl RelayListUpdater { /// Write a `RelayList` to the cache file. async fn cache_relays(cache_path: &Path, relays: &RelayList) -> Result<(), Error> { - debug!("Writing relays cache to {}", cache_path.display()); + log::debug!("Writing relays cache to {}", cache_path.display()); let mut file = File::create(cache_path) .await .map_err(Error::OpenRelayCache)?; |
