Skip to content

Commit 507a268

Browse files
authored
Use correct logging filename (#714)
1 parent 19af6ce commit 507a268

File tree

4 files changed

+33
-39
lines changed

4 files changed

+33
-39
lines changed

src-tauri/src/bin/defguard-client.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use defguard_client::{
2929
service,
3030
tray::{configure_tray_icon, setup_tray, show_main_window},
3131
utils::load_log_targets,
32-
VERSION,
32+
LOG_FILENAME, VERSION,
3333
};
3434
use log::{Level, LevelFilter};
3535
use tauri::{AppHandle, Builder, Manager, RunEvent, WindowEvent};
@@ -286,7 +286,7 @@ fn main() {
286286
})
287287
.targets([
288288
Target::new(TargetKind::Stdout),
289-
Target::new(TargetKind::LogDir { file_name: None }),
289+
Target::new(TargetKind::LogDir { file_name: Some(LOG_FILENAME.to_string()) }),
290290
])
291291
.level(log_level)
292292
.filter(|metadata| {
@@ -364,9 +364,11 @@ fn main() {
364364
}
365365

366366
info!(
367-
"Application data (database file) will be stored in: {data_dir:?} and application \
368-
logs in: {log_dir:?}. Logs of the background Defguard service responsible for \
369-
managing VPN connections at the network level will be stored in: {}.",
367+
"Application data (database file) will be stored in: {} and application logs in: \
368+
{}. Logs of the background Defguard service responsible for managing VPN \
369+
connections at the network level will be stored in: {}.",
370+
data_dir.display(),
371+
log_dir.display(),
370372
service::config::DEFAULT_LOG_DIR
371373
);
372374
tauri::async_runtime::block_on(startup(app_handle));

src-tauri/src/enterprise/provisioning/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,16 @@ pub async fn handle_client_initialization(app_handle: &AppHandle) -> Option<Prov
8383
.unwrap_or_else(|_| "UNDEFINED DATA DIRECTORY".into());
8484
match try_get_provisioning_config(&data_dir) {
8585
Some(config) => {
86-
info!("Provisioning config found in {data_dir:?}: {config:?}");
86+
info!(
87+
"Provisioning config found in {}: {config:?}",
88+
data_dir.display()
89+
);
8790
return Some(config);
8891
}
8992
None => {
9093
debug!(
91-
"Provisioning config not found in {data_dir:?}. Proceeding with normal \
92-
startup."
94+
"Provisioning config not found in {}. Proceeding with normal startup.",
95+
data_dir.display()
9396
);
9497
}
9598
}

src-tauri/src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ pub const MIN_PROXY_VERSION: Version = Version::new(1, 6, 0);
3939
pub const CLIENT_VERSION_HEADER: &str = "defguard-client-version";
4040
pub const CLIENT_PLATFORM_HEADER: &str = "defguard-client-platform";
4141
pub const PKG_VERSION: &str = env!("CARGO_PKG_VERSION");
42+
// Must be without ".log" suffix!
43+
pub const LOG_FILENAME: &str = "defguard-client";
4244
// This must match tauri.bundle.identifier from tauri.conf.json.
4345
const BUNDLE_IDENTIFIER: &str = "net.defguard";
4446
// Returns the path to the user's data directory.
@@ -54,7 +56,10 @@ pub fn app_data_dir() -> Option<PathBuf> {
5456
pub fn set_perms(path: &Path) {
5557
let perms = if path.is_dir() { 0o700 } else { 0o600 };
5658
if let Err(err) = set_permissions(path, Permissions::from_mode(perms)) {
57-
warn!("Failed to set permissions on path {path:?}: {err}");
59+
warn!(
60+
"Failed to set permissions on path {}: {err}",
61+
path.display()
62+
);
5863
}
5964
}
6065

src-tauri/src/log_watcher/global_log_watcher.rs

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use chrono::NaiveDate;
1717
use chrono::{DateTime, NaiveDateTime, TimeZone, Utc};
1818
use regex::Regex;
1919
use tauri::{async_runtime::JoinHandle, AppHandle, Emitter, Manager};
20+
use tokio::time::sleep;
2021
use tokio_util::sync::CancellationToken;
2122
use tracing::Level;
2223

@@ -26,6 +27,7 @@ use crate::{
2627
appstate::AppState,
2728
error::Error,
2829
log_watcher::{LogLine, LogLineFields, LogSource, LogWatcherError},
30+
LOG_FILENAME,
2931
};
3032
#[cfg(not(target_os = "macos"))]
3133
use crate::{log_watcher::extract_timestamp, utils::get_service_log_dir};
@@ -125,42 +127,24 @@ impl LogDirs {
125127

126128
#[cfg(not(target_os = "macos"))]
127129
fn get_current_service_file(&self) -> Result<File, LogWatcherError> {
128-
trace!(
129-
"Opening service log file: {:?}",
130-
self.current_service_log_file
131-
);
132130
match &self.current_service_log_file {
133131
Some(path) => {
132+
trace!("Opening service log file: {}", path.display());
134133
let file = File::open(path)?;
135-
trace!(
136-
"Successfully opened service log file at {:?}",
137-
self.current_service_log_file
138-
);
134+
trace!("Successfully opened service log file at {}", path.display());
139135
Ok(file)
140136
}
141-
None => Err(LogWatcherError::LogPathError(format!(
142-
"Couldn't find service log file at: {:?}",
143-
self.current_service_log_file
144-
))),
137+
None => Err(LogWatcherError::LogPathError(
138+
"Service log file not defined".to_string(),
139+
)),
145140
}
146141
}
147142

148143
fn get_client_file(&self) -> Result<File, LogWatcherError> {
149-
trace!(
150-
"Opening the log file for the client, using directory: {}",
151-
self.client_log_dir.display()
152-
);
153-
let dir_str = self
154-
.client_log_dir
155-
.to_str()
156-
.ok_or(LogWatcherError::LogPathError(format!(
157-
"Couldn't convert the client log directory path ({}) to a string slice",
158-
self.client_log_dir.display()
159-
)))?;
160-
let path = format!("{dir_str}/defguard-client.log");
161-
trace!("Constructed client log file path: {path}");
144+
let path = self.client_log_dir.join(format!("{LOG_FILENAME}.log"));
145+
trace!("Constructed client log file path: {}", path.display());
162146
let file = File::open(&path)?;
163-
trace!("Client log file at {path:?} opened successfully");
147+
trace!("Client log file at {} opened successfully", path.display());
164148
Ok(file)
165149
}
166150

@@ -243,7 +227,7 @@ impl GlobalLogWatcher {
243227
self.log_dirs.client_log_dir.display()
244228
);
245229
// Wait for logs to appear.
246-
tokio::time::sleep(DELAY).await;
230+
sleep(DELAY).await;
247231
return Ok(());
248232
}
249233
debug!("Log files are available, starting to read lines.");
@@ -335,7 +319,7 @@ impl GlobalLogWatcher {
335319
parsed_lines.clear();
336320
}
337321
trace!("Sleeping for {DELAY:?} seconds before reading again");
338-
tokio::time::sleep(DELAY).await;
322+
sleep(DELAY).await;
339323
}
340324

341325
Ok(())
@@ -368,7 +352,7 @@ impl GlobalLogWatcher {
368352
self.log_dirs.vpn_extension_log_dir.display()
369353
);
370354
// Wait for logs to appear.
371-
tokio::time::sleep(DELAY).await;
355+
sleep(DELAY).await;
372356
return Ok(());
373357
}
374358
debug!("Log files are available, starting to read lines.");
@@ -450,7 +434,7 @@ impl GlobalLogWatcher {
450434
parsed_lines.clear();
451435
}
452436
trace!("Sleeping for {DELAY:?} seconds before reading again");
453-
tokio::time::sleep(DELAY).await;
437+
sleep(DELAY).await;
454438
}
455439

456440
Ok(())

0 commit comments

Comments
 (0)