File tree Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -345,6 +345,13 @@ async fn serve_with_csa(
345345 log = log. tee ( log_broadcast. clone ( ) ) ;
346346 log:: install_global_logger ( log. clone ( ) ) ; // re-install so that library logs are captured
347347
348+ debug ! (
349+ log,
350+ "Starting tunnel with `{} {}`" ,
351+ APPLICATION_NAME ,
352+ std:: env:: args( ) . collect:: <Vec <_>>( ) . join( " " )
353+ ) ;
354+
348355 // Intentionally read before starting the server. If the server updated and
349356 // respawn is requested, the old binary will get renamed, and then
350357 // current_exe will point to the wrong path.
@@ -435,7 +442,10 @@ async fn serve_with_csa(
435442
436443 return Ok ( exit. code ( ) . unwrap_or ( 1 ) ) ;
437444 }
438- Next :: Exit => return Ok ( 0 ) ,
445+ Next :: Exit => {
446+ debug ! ( log, "Tunnel shut down" ) ;
447+ return Ok ( 0 ) ;
448+ }
439449 Next :: Restart => continue ,
440450 }
441451 }
Original file line number Diff line number Diff line change @@ -159,9 +159,21 @@ pub struct FileLogSink {
159159 file : Arc < std:: sync:: Mutex < std:: fs:: File > > ,
160160}
161161
162+ const FILE_LOG_SIZE_LIMIT : u64 = 1024 * 1024 * 10 ; // 10MB
163+
162164impl FileLogSink {
163165 pub fn new ( level : Level , path : & Path ) -> std:: io:: Result < Self > {
164- let file = std:: fs:: File :: create ( path) ?;
166+ // Truncate the service log occasionally to avoid growing infinitely
167+ if matches ! ( path. metadata( ) , Ok ( m) if m. len( ) > FILE_LOG_SIZE_LIMIT ) {
168+ // ignore errors, can happen if another process is writing right now
169+ let _ = std:: fs:: remove_file ( path) ;
170+ }
171+
172+ let file = std:: fs:: OpenOptions :: new ( )
173+ . append ( true )
174+ . create ( true )
175+ . open ( path) ?;
176+
165177 Ok ( Self {
166178 level,
167179 file : Arc :: new ( std:: sync:: Mutex :: new ( file) ) ,
You can’t perform that action at this time.
0 commit comments