Fall back to stdout if log file is inaccessible (#8415)
https://github.com/zed-industries/zed/assets/31967125/644f3524-e680-457c-bf4c-a7f11f3ec8db Fixes #8209 Defaults to env logger in case of open/access failure. Release Notes: - Improved Zed behavior when no log file access is possible ([8209](https://github.com/zed-industries/zed/issues/8209)) --------- Co-authored-by: Kirill Bulatov <mail4score@gmail.com>
This commit is contained in:
parent
8fc2431a2a
commit
af14bc7a27
2 changed files with 78 additions and 47 deletions
|
@ -477,25 +477,42 @@ fn open_log_file(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) {
|
|||
cx.spawn(|workspace, mut cx| async move {
|
||||
let (old_log, new_log) =
|
||||
futures::join!(fs.load(&paths::OLD_LOG), fs.load(&paths::LOG));
|
||||
|
||||
let mut lines = VecDeque::with_capacity(MAX_LINES);
|
||||
for line in old_log
|
||||
.iter()
|
||||
.flat_map(|log| log.lines())
|
||||
.chain(new_log.iter().flat_map(|log| log.lines()))
|
||||
{
|
||||
if lines.len() == MAX_LINES {
|
||||
lines.pop_front();
|
||||
let log = match (old_log, new_log) {
|
||||
(Err(_), Err(_)) => None,
|
||||
(old_log, new_log) => {
|
||||
let mut lines = VecDeque::with_capacity(MAX_LINES);
|
||||
for line in old_log
|
||||
.iter()
|
||||
.flat_map(|log| log.lines())
|
||||
.chain(new_log.iter().flat_map(|log| log.lines()))
|
||||
{
|
||||
if lines.len() == MAX_LINES {
|
||||
lines.pop_front();
|
||||
}
|
||||
lines.push_back(line);
|
||||
}
|
||||
Some(
|
||||
lines
|
||||
.into_iter()
|
||||
.flat_map(|line| [line, "\n"])
|
||||
.collect::<String>(),
|
||||
)
|
||||
}
|
||||
lines.push_back(line);
|
||||
}
|
||||
let log = lines
|
||||
.into_iter()
|
||||
.flat_map(|line| [line, "\n"])
|
||||
.collect::<String>();
|
||||
};
|
||||
|
||||
workspace
|
||||
.update(&mut cx, |workspace, cx| {
|
||||
let Some(log) = log else {
|
||||
workspace.show_notification(29, cx, |cx| {
|
||||
cx.new_view(|_| {
|
||||
MessageNotification::new(format!(
|
||||
"Unable to access/open log file at path {:?}",
|
||||
paths::LOG.as_path()
|
||||
))
|
||||
})
|
||||
});
|
||||
return;
|
||||
};
|
||||
let project = workspace.project().clone();
|
||||
let buffer = project
|
||||
.update(cx, |project, cx| project.create_buffer("", None, cx))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue