Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(layers/logging): parsing level str #2160

Merged
merged 6 commits into from
Apr 29, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions core/src/layers/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,11 @@ impl LoggingLayer {
/// `None` means disable the log for error.
pub fn with_error_level(mut self, level: Option<&str>) -> Result<Self> {
if let Some(level) = level {
let level = Level::from_str(level).expect("parse level must succeed");
self.error_level = Some(level);
if let Ok(level) = Level::from_str(level) {
PsiACE marked this conversation as resolved.
Show resolved Hide resolved
self.error_level = Some(level);
return Ok(self);
}
return Err(Error::new(ErrorKind::ConfigInvalid, "invalid log level"));
} else {
self.error_level = None;
}
Expand All @@ -123,8 +126,11 @@ impl LoggingLayer {
/// `None` means disable the log for failure.
pub fn with_failure_level(mut self, level: Option<&str>) -> Result<Self> {
if let Some(level) = level {
let level = Level::from_str(level).expect("parse level must succeed");
self.failure_level = Some(level);
if let Ok(level) = Level::from_str(level) {
self.failure_level = Some(level);
return Ok(self);
}
return Err(Error::new(ErrorKind::ConfigInvalid, "invalid log level"));
} else {
self.failure_level = None;
}
Expand Down