mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-20 02:08:47 +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 = log.tee(log_broadcast.clone());
|
||||||
log::install_global_logger(log.clone()); // re-install so that library logs are captured
|
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
|
// Intentionally read before starting the server. If the server updated and
|
||||||
// respawn is requested, the old binary will get renamed, and then
|
// respawn is requested, the old binary will get renamed, and then
|
||||||
// current_exe will point to the wrong path.
|
// current_exe will point to the wrong path.
|
||||||
@@ -435,7 +442,10 @@ async fn serve_with_csa(
|
|||||||
|
|
||||||
return Ok(exit.code().unwrap_or(1));
|
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,
|
Next::Restart => continue,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -159,9 +159,21 @@ pub struct FileLogSink {
|
|||||||
file: Arc<std::sync::Mutex<std::fs::File>>,
|
file: Arc<std::sync::Mutex<std::fs::File>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const FILE_LOG_SIZE_LIMIT: u64 = 1024 * 1024 * 10; // 10MB
|
||||||
|
|
||||||
impl FileLogSink {
|
impl FileLogSink {
|
||||||
pub fn new(level: Level, path: &Path) -> std::io::Result<Self> {
|
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 {
|
Ok(Self {
|
||||||
level,
|
level,
|
||||||
file: Arc::new(std::sync::Mutex::new(file)),
|
file: Arc::new(std::sync::Mutex::new(file)),
|
||||||
|
|||||||
Reference in New Issue
Block a user