@@ -17,6 +17,7 @@ use chrono::NaiveDate;
1717use chrono:: { DateTime , NaiveDateTime , TimeZone , Utc } ;
1818use regex:: Regex ;
1919use tauri:: { async_runtime:: JoinHandle , AppHandle , Emitter , Manager } ;
20+ use tokio:: time:: sleep;
2021use tokio_util:: sync:: CancellationToken ;
2122use 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" ) ) ]
3133use 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