Skip to content

Commit db70a7a

Browse files
committed
add even more logs
1 parent 2e6f39d commit db70a7a

File tree

5 files changed

+110
-33
lines changed

5 files changed

+110
-33
lines changed

src-tauri/src/appstate.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ impl AppState {
7171
info!("Removed connection from active connections: {removed_connection:#?}");
7272
Some(removed_connection)
7373
} else {
74+
debug!("No active connection found with location_id: {location_id}");
7475
None
7576
}
7677
}
@@ -97,11 +98,15 @@ impl AppState {
9798
let active_connections = self.get_connections();
9899
info!("Found {} active connections", active_connections.len());
99100
for connection in active_connections {
100-
debug!("Found active connection");
101+
debug!(
102+
"Found active connection with location {}",
103+
connection.location_id
104+
);
101105
trace!("Connection: {connection:#?}");
102-
debug!("Removing interface");
106+
debug!("Removing interface {}", connection.interface_name);
103107
disconnect_interface(connection, self).await?;
104108
}
109+
info!("All active connections closed");
105110
Ok(())
106111
}
107112

@@ -123,7 +128,7 @@ impl AppState {
123128
debug!("Found connection: {connection:#?}");
124129
Some(connection.to_owned())
125130
} else {
126-
error!("Element with id: {id}, connection_type: {connection_type:?} not found.");
131+
error!("Couldn't find connection with id: {id}, connection_type: {connection_type:?} in active connections.");
127132
None
128133
}
129134
}

src-tauri/src/commands.rs

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub async fn disconnect(
7878
info!("Disconnected from location with id: {location_id}");
7979
Ok(())
8080
} else {
81-
error!("Connection for location with id: {location_id} not found");
81+
error!("Error while disconnecting from location with id: {location_id} not found");
8282
Err(Error::NotFound)
8383
}
8484
}
@@ -130,7 +130,7 @@ pub async fn save_device_config(
130130
app_state: State<'_, AppState>,
131131
handle: AppHandle,
132132
) -> Result<SaveDeviceConfigResponse, Error> {
133-
debug!("Received device configuration: {response:#?}");
133+
debug!("Received device configuration: {response:#?}.");
134134

135135
let mut transaction = app_state.get_pool().begin().await?;
136136
let instance_info = response
@@ -168,6 +168,7 @@ pub async fn save_device_config(
168168
locations,
169169
instance,
170170
};
171+
info!("Device configuration saved.");
171172
Ok(res)
172173
}
173174

@@ -309,6 +310,7 @@ pub async fn update_instance(
309310
let mut transaction = pool.begin().await?;
310311

311312
// update instance
313+
debug!("Updating instance {instance_id}.");
312314
let instance_info = response
313315
.instance
314316
.expect("Missing instance info in device config response");
@@ -319,6 +321,7 @@ pub async fn update_instance(
319321
instance.save(&mut *transaction).await?;
320322

321323
// process locations received in response
324+
debug!("Updating locations for instance {instance_id}.");
322325
for location in response.configs {
323326
// parse device config
324327
let mut new_location = device_config_to_location(location, instance_id);
@@ -330,6 +333,10 @@ pub async fn update_instance(
330333
{
331334
// remove from list of existing locations
332335
let mut current_location = current_locations.remove(position);
336+
debug!(
337+
"Updating existing location {} for instance {instance_id}.",
338+
current_location.name
339+
);
333340
// update existing location
334341
current_location.name = new_location.name;
335342
current_location.address = new_location.address;
@@ -339,17 +346,26 @@ pub async fn update_instance(
339346
current_location.mfa_enabled = new_location.mfa_enabled;
340347
current_location.keepalive_interval = new_location.keepalive_interval;
341348
current_location.save(&mut *transaction).await?;
349+
info!(
350+
"Location {} updated for instance {instance_id}.",
351+
current_location.name
352+
);
342353
} else {
343354
// create new location
355+
debug!("Creating new location for instance {instance_id}.");
344356
new_location.save(&mut *transaction).await?;
357+
info!("New location created for instance {instance_id}.");
345358
}
346359
}
360+
info!("Locations updated for instance {instance_id}.");
347361

348362
// remove locations which were present in current locations
349363
// but no longer found in core response
364+
debug!("Removing locations for instance {instance_id}.");
350365
for removed_location in current_locations {
351366
removed_location.delete(&mut *transaction).await?;
352367
}
368+
info!("Locations removed for instance {instance_id}.");
353369

354370
transaction.commit().await?;
355371

@@ -456,7 +472,7 @@ pub async fn all_connections(
456472
.collect()
457473
}
458474
};
459-
debug!("Connections received, returning.");
475+
info!("Connections retrieved({})", connections.len());
460476
trace!("Connections found:\n{:#?}", connections);
461477
Ok(connections)
462478
}
@@ -469,7 +485,7 @@ pub async fn all_tunnel_connections(
469485
debug!("Retrieving connections for location {location_id}");
470486
let connections =
471487
TunnelConnectionInfo::all_by_tunnel_id(&app_state.get_pool(), location_id).await?;
472-
debug!("Connections received, returning.");
488+
info!("Tunnel connections retrieved({})", connections.len());
473489
trace!("Connections found:\n{:#?}", connections);
474490
Ok(connections)
475491
}
@@ -487,8 +503,8 @@ pub async fn active_connection(
487503
if connection.is_some() {
488504
debug!("Active connection found");
489505
}
490-
trace!("Connection:\n{:#?}", connection);
491-
debug!("Connection returned");
506+
trace!("Connection retrieved:\n{:#?}", connection);
507+
info!("Connection retrieved");
492508
Ok(connection)
493509
}
494510

@@ -503,18 +519,18 @@ pub async fn last_connection(
503519
if let Some(connection) =
504520
Connection::latest_by_location_id(&app_state.get_pool(), location_id).await?
505521
{
506-
trace!("Connection found");
522+
info!("Found last connection at {}", connection.end);
507523
Ok(Some(connection.into()))
508524
} else {
509525
Ok(None)
510526
}
511527
} else if let Some(connection) =
512528
TunnelConnection::latest_by_tunnel_id(&app_state.get_pool(), location_id).await?
513529
{
514-
trace!("Connection found");
530+
info!("Found last connection at {}", connection.end);
515531
Ok(Some(connection.into()))
516532
} else {
517-
trace!("No last connection found");
533+
info!("No last connection found");
518534
Ok(None)
519535
}
520536
}
@@ -536,7 +552,7 @@ pub async fn update_location_routing(
536552
{
537553
location.route_all_traffic = route_all_traffic;
538554
location.save(&app_state.get_pool()).await?;
539-
debug!("Location routing updated for location {location_id}");
555+
info!("Location routing updated for location {location_id}");
540556
handle.emit_all(
541557
"location-update",
542558
Payload {
@@ -556,7 +572,7 @@ pub async fn update_location_routing(
556572
{
557573
tunnel.route_all_traffic = route_all_traffic;
558574
tunnel.save(&app_state.get_pool()).await?;
559-
debug!("Tunnel routing updated for tunnel {location_id}");
575+
info!("Tunnel routing updated for tunnel {location_id}");
560576
handle.emit_all(
561577
"location-update",
562578
Payload {
@@ -577,6 +593,7 @@ pub async fn get_settings(handle: AppHandle) -> Result<Settings, Error> {
577593
debug!("Retrieving settings");
578594
let app_state = handle.state::<AppState>();
579595
let settings = Settings::get(&app_state.get_pool()).await?;
596+
info!("Settings retrieved");
580597
Ok(settings)
581598
}
582599

@@ -595,7 +612,7 @@ pub async fn update_settings(data: SettingsPatch, handle: AppHandle) -> Result<S
595612
Ok(_) => {}
596613
Err(e) => {
597614
error!(
598-
"During settings update, tray configuration update failed. err : {}",
615+
"Tray configuration update failed during settings update. err : {}",
599616
e.to_string()
600617
);
601618
}
@@ -632,7 +649,7 @@ pub async fn delete_instance(instance_id: i64, handle: AppHandle) -> Result<(),
632649
error!("{msg}");
633650
Error::InternalError(msg)
634651
})?;
635-
debug!("Connection closed and interface removed");
652+
info!("Connection closed and interface removed");
636653
}
637654
}
638655
}
@@ -648,10 +665,12 @@ pub async fn delete_instance(instance_id: i64, handle: AppHandle) -> Result<(),
648665
#[tauri::command(async)]
649666
pub async fn parse_tunnel_config(config: String) -> Result<Tunnel, Error> {
650667
debug!("Parsing config file");
651-
parse_wireguard_config(&config).map_err(|error| {
668+
let tunnel_config = parse_wireguard_config(&config).map_err(|error| {
652669
error!("{error}");
653670
Error::ConfigParseError(error.to_string())
654-
})
671+
})?;
672+
info!("Config file parsed");
673+
Ok(tunnel_config)
655674
}
656675
#[tauri::command(async)]
657676
pub async fn save_tunnel(mut tunnel: Tunnel, handle: AppHandle) -> Result<(), Error> {
@@ -700,6 +719,8 @@ pub async fn all_tunnels(app_state: State<'_, AppState>) -> Result<Vec<TunnelInf
700719
connection_type: ConnectionType::Tunnel,
701720
})
702721
}
722+
723+
info!("Tunnels retrieved({})", tunnel_info.len());
703724
Ok(tunnel_info)
704725
}
705726
#[tauri::command(async)]
@@ -710,7 +731,7 @@ pub async fn tunnel_details(
710731
debug!("Retrieving Tunnel with ID {tunnel_id}.");
711732

712733
if let Some(tunnel) = Tunnel::find_by_id(&app_state.get_pool(), tunnel_id).await? {
713-
debug!("Found tunnel {tunnel_id}");
734+
info!("Found tunnel {tunnel_id}");
714735
Ok(tunnel)
715736
} else {
716737
error!("Tunnel with ID: {tunnel_id}, not found");
@@ -745,7 +766,7 @@ pub async fn delete_tunnel(tunnel_id: i64, handle: AppHandle) -> Result<(), Erro
745766
error!("{msg}");
746767
Error::InternalError(msg)
747768
})?;
748-
debug!("Connection closed and interface removed");
769+
info!("Connection closed and interface removed");
749770
}
750771
tunnel.delete(pool).await?;
751772
} else {
@@ -798,10 +819,13 @@ pub async fn get_latest_app_version(handle: AppHandle) -> Result<AppVersionInfo,
798819
let response_json: Result<AppVersionInfo, reqwest::Error> =
799820
response.json::<AppVersionInfo>().await;
800821

801-
response_json.map_err(|err| {
822+
let response = response_json.map_err(|err| {
802823
error!("Failed to deserialize latest application version response {err}");
803824
Error::CommandError(err.to_string())
804-
})
825+
})?;
826+
827+
info!("Latest application version fetched: {}", response.version);
828+
Ok(response)
805829
} else {
806830
let err = res.err().unwrap();
807831
error!("Failed to fetch latest application version {err}");

src-tauri/src/service/log_watcher.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ impl ServiceLogWatcher {
142142
fn parse_log_dir(&mut self) -> Result<(), LogWatcherError> {
143143
// get latest log file
144144
let latest_log_file = self.get_latest_log_file()?;
145-
info!("found latest log file: {latest_log_file:?}");
145+
debug!("found latest log file: {latest_log_file:?}");
146146

147147
// check if latest file changed
148148
if latest_log_file.is_some() && latest_log_file != self.current_log_file {
@@ -180,9 +180,9 @@ impl ServiceLogWatcher {
180180
/// Deserializes the log line into a known struct and checks if the line is relevant
181181
/// to the specified interface. Also performs filtering by log level and optional timestamp.
182182
fn parse_log_line(&self, line: String) -> Result<Option<LogLine>, LogWatcherError> {
183-
debug!("Parsing log line: {line}");
183+
trace!("Parsing log line: {line}");
184184
let log_line = serde_json::from_str::<LogLine>(&line)?;
185-
debug!("Parsed log line into: {log_line:?}");
185+
trace!("Parsed log line into: {log_line:?}");
186186

187187
// filter by log level
188188
if log_line.level > self.log_level {
@@ -205,7 +205,7 @@ impl ServiceLogWatcher {
205205
if let Some(ref span) = log_line.span {
206206
if let Some(interface_name) = &span.interface_name {
207207
if interface_name != &self.interface_name {
208-
debug!("Interface name {interface_name} is not the configured name {}. Skipping line...", self.interface_name);
208+
trace!("Interface name {interface_name} is not the configured name {}. Skipping line...", self.interface_name);
209209
return Ok(None);
210210
}
211211
}
@@ -244,7 +244,7 @@ impl ServiceLogWatcher {
244244
}
245245

246246
fn extract_timestamp(filename: &str) -> Option<SystemTime> {
247-
debug!("Extracting timestamp from log file name: {filename}");
247+
trace!("Extracting timestamp from log file name: {filename}");
248248
// we know that the date is always in the last 10 characters
249249
let split_pos = filename.char_indices().nth_back(9)?.0;
250250
let timestamp = &filename[split_pos..];

src-tauri/src/tray.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ pub fn configure_tray_icon(app: &AppHandle, theme: &TrayIconTheme) -> Result<(),
101101
Some(icon_path) => {
102102
let icon = tauri::Icon::File(icon_path);
103103
app.tray_handle().set_icon(icon)?;
104-
debug!("Tray icon changed");
104+
info!("Tray icon changed");
105105
Ok(())
106106
}
107107
None => {

0 commit comments

Comments
 (0)