mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-19 17:58:39 +00:00
cli: log startup and shutdown, don't clear service logs on restart
Fixes #183696
This commit is contained in:
@@ -345,6 +345,13 @@ async fn serve_with_csa(
|
||||
log = log.tee(log_broadcast.clone());
|
||||
log::install_global_logger(log.clone()); // re-install so that library logs are captured
|
||||
|
||||
debug!(
|
||||
log,
|
||||
"Starting tunnel with `{} {}`",
|
||||
APPLICATION_NAME,
|
||||
std::env::args().collect::<Vec<_>>().join(" ")
|
||||
);
|
||||
|
||||
// Intentionally read before starting the server. If the server updated and
|
||||
// respawn is requested, the old binary will get renamed, and then
|
||||
// current_exe will point to the wrong path.
|
||||
@@ -435,7 +442,10 @@ async fn serve_with_csa(
|
||||
|
||||
return Ok(exit.code().unwrap_or(1));
|
||||
}
|
||||
Next::Exit => return Ok(0),
|
||||
Next::Exit => {
|
||||
debug!(log, "Tunnel shut down");
|
||||
return Ok(0);
|
||||
}
|
||||
Next::Restart => continue,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,9 +159,21 @@ pub struct FileLogSink {
|
||||
file: Arc<std::sync::Mutex<std::fs::File>>,
|
||||
}
|
||||
|
||||
const FILE_LOG_SIZE_LIMIT: u64 = 1024 * 1024 * 10; // 10MB
|
||||
|
||||
impl FileLogSink {
|
||||
pub fn new(level: Level, path: &Path) -> std::io::Result<Self> {
|
||||
let file = std::fs::File::create(path)?;
|
||||
// Truncate the service log occasionally to avoid growing infinitely
|
||||
if matches!(path.metadata(), Ok(m) if m.len() > FILE_LOG_SIZE_LIMIT) {
|
||||
// ignore errors, can happen if another process is writing right now
|
||||
let _ = std::fs::remove_file(path);
|
||||
}
|
||||
|
||||
let file = std::fs::OpenOptions::new()
|
||||
.append(true)
|
||||
.create(true)
|
||||
.open(path)?;
|
||||
|
||||
Ok(Self {
|
||||
level,
|
||||
file: Arc::new(std::sync::Mutex::new(file)),
|
||||
|
||||
Reference in New Issue
Block a user