forked from zed-industries/zed
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve ssh remote error handling and logging (zed-industries#15035)
Release Notes: - N/A
- Loading branch information
1 parent
6443671
commit b8cec9b
Showing
10 changed files
with
103 additions
and
16 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use log::{Level, Log, Record}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Deserialize, Debug, Serialize)] | ||
pub struct LogRecord<'a> { | ||
pub level: usize, | ||
pub module_path: Option<&'a str>, | ||
pub file: Option<&'a str>, | ||
pub line: Option<u32>, | ||
pub message: String, | ||
} | ||
|
||
impl<'a> LogRecord<'a> { | ||
pub fn new(record: &'a Record<'a>) -> Self { | ||
Self { | ||
level: serialize_level(record.level()), | ||
module_path: record.module_path(), | ||
file: record.file(), | ||
line: record.line(), | ||
message: record.args().to_string(), | ||
} | ||
} | ||
|
||
pub fn log(&'a self, logger: &dyn Log) { | ||
if let Some(level) = deserialize_level(self.level) { | ||
logger.log( | ||
&log::Record::builder() | ||
.module_path(self.module_path) | ||
.target("remote_server") | ||
.args(format_args!("{}", self.message)) | ||
.file(self.file) | ||
.line(self.line) | ||
.level(level) | ||
.build(), | ||
) | ||
} | ||
} | ||
} | ||
|
||
fn serialize_level(level: Level) -> usize { | ||
match level { | ||
Level::Error => 1, | ||
Level::Warn => 2, | ||
Level::Info => 3, | ||
Level::Debug => 4, | ||
Level::Trace => 5, | ||
} | ||
} | ||
|
||
fn deserialize_level(level: usize) -> Option<Level> { | ||
match level { | ||
1 => Some(Level::Error), | ||
2 => Some(Level::Warn), | ||
3 => Some(Level::Info), | ||
4 => Some(Level::Debug), | ||
5 => Some(Level::Trace), | ||
_ => None, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod json_log; | ||
pub mod protocol; | ||
pub mod ssh_session; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters