-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Specify log file through API #250
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a4d8e32
api_server: adding support for specifying log file...
dianpopa 66536df
logger: ensuring thread safety for logger's initialization
dianpopa c44371f
logger: update unit tests
dianpopa 8fc25c5
api_server: added unit tests for the logger description
dianpopa 4c6bd25
vmm: unit testing the logger configuration...
dianpopa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,126 @@ | ||
use std::result; | ||
|
||
use futures::sync::oneshot; | ||
use hyper::{Response, StatusCode}; | ||
|
||
use http_service::{empty_response, json_fault_message, json_response}; | ||
use request::{ParsedRequest, SyncRequest}; | ||
use request::sync::GenerateResponse; | ||
|
||
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] | ||
pub enum APILoggerLevel { | ||
Error, | ||
Warning, | ||
Info, | ||
Debug, | ||
} | ||
|
||
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] | ||
pub struct APILoggerDescription { | ||
pub path: String, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub level: Option<APILoggerLevel>, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub show_level: Option<bool>, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub show_log_origin: Option<bool>, | ||
} | ||
|
||
#[derive(Debug)] | ||
pub enum APILoggerError { | ||
InitializationFailure(String), | ||
} | ||
|
||
impl GenerateResponse for APILoggerError { | ||
fn generate_response(&self) -> Response { | ||
use self::APILoggerError::*; | ||
match *self { | ||
InitializationFailure(ref e) => json_response( | ||
StatusCode::BadRequest, | ||
json_fault_message(format!{"Cannot initialize logging system! {}", e}), | ||
), | ||
} | ||
} | ||
} | ||
|
||
pub enum PutLoggerOutcome { | ||
Initialized, | ||
Error(APILoggerError), | ||
} | ||
|
||
impl GenerateResponse for PutLoggerOutcome { | ||
fn generate_response(&self) -> Response { | ||
use self::PutLoggerOutcome::*; | ||
match *self { | ||
Initialized => empty_response(StatusCode::Created), | ||
Error(ref e) => e.generate_response(), | ||
} | ||
} | ||
} | ||
|
||
impl APILoggerDescription { | ||
pub fn into_parsed_request(self) -> result::Result<ParsedRequest, String> { | ||
let (sender, receiver) = oneshot::channel(); | ||
Ok(ParsedRequest::Sync( | ||
SyncRequest::PutLogger(self, sender), | ||
receiver, | ||
)) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_generate_response_logger_error() { | ||
assert_eq!( | ||
APILoggerError::InitializationFailure("Could not initialize log system".to_string()) | ||
.generate_response() | ||
.status(), | ||
StatusCode::BadRequest | ||
); | ||
assert!( | ||
format!( | ||
"{:?}", | ||
APILoggerError::InitializationFailure( | ||
"Could not initialize log system".to_string() | ||
) | ||
).contains("InitializationFailure") | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_generate_response_put_logger_outcome() { | ||
assert_eq!( | ||
PutLoggerOutcome::Initialized.generate_response().status(), | ||
StatusCode::Created | ||
); | ||
assert_eq!( | ||
PutLoggerOutcome::Error(APILoggerError::InitializationFailure( | ||
"Could not initialize log system".to_string() | ||
)).generate_response() | ||
.status(), | ||
StatusCode::BadRequest | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_into_parsed_request() { | ||
let desc = APILoggerDescription { | ||
path: String::from(""), | ||
level: None, | ||
show_level: None, | ||
show_log_origin: None, | ||
}; | ||
format!("{:?}", desc); | ||
assert!(&desc.clone().into_parsed_request().is_ok()); | ||
let (sender, receiver) = oneshot::channel(); | ||
assert!(&desc.clone() | ||
.into_parsed_request() | ||
.eq(&Ok(ParsedRequest::Sync( | ||
SyncRequest::PutLogger(desc, sender), | ||
receiver | ||
)))); | ||
} | ||
} |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add these to firecracker-v1.0.yaml as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We discussed about it yesterday. firecracker-v1.0.yaml is very outdated. So we have here two possibilities: either update it to match what we have now in firecracker-beta, or we don't update it at all for now and only use it as a " What the future looks like" yaml. Since we are sort of time bound, I suggest we don't update it for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok